Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I need to write some app which may contain several classes etc.
I am thinking to take care of error management using error codes.
I am just thinking what are the techniques usually taken to
avoid collisions between error code names?

Or shall I have all error codes have unique names and put all of them in one
header file for example?

Thanks.
Posted
Comments
Philippe Mori 16-May-13 18:51pm    
As mentionned in solution 2, it is better to uses exceptions. If you really need a code, then why not use an enumeration that it is specific to the exception class. Most of the time, you don't really need to know the exact reason why an error was raised and usually you would write a generic message to the user and possibly give the possibility to see détails)
Volynsky Alex 17-May-13 5:10am    
please read following post:
https://groups.google.com/forum/?fromgroups#!topic/closure-compiler-discuss/fxnPHdfiaiI

The second choice sounds the best idea; which looks better out of the following?
C++
if (sometest)
    throw 27;
//
if (sometest)
    throw illegaldoofus;
 
Share this answer
 
Comments
Dan page 16-May-13 9:34am    
yes, I 'll probably have unique names for each error (which also makes sense) and then return appropriate ones from different functions etc... thanks
Richard MacCutchan 16-May-13 9:37am    
I'm not sure whether it has been superceded, but I have used the Message Compiler system to auto-generate message codes and associated message text, in some projects in the past.
Sergey Alexandrovich Kryukov 16-May-13 10:07am    
I think all OP's approaches are not acceptable, they are based on thinking before the time exceptions were invented. Please see my answer.
—SA
With structured exception handling, you don't need "error codes" but you need exception classes. Forget about this old trash and learn how exceptions work. This mechanism revolutionized development more than OOP and many other technologies, it allows you, roughly speaking, to stop worrying about "errors" and start programming.

—SA
 
Share this answer
 
Comments
Leo Chapiro 16-May-13 10:26am    
Exactly my point of view, +5 !
Sergey Alexandrovich Kryukov 16-May-13 10:29am    
Thank you,
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900