Hello all,
I have a question here: In a large C++ project, how would you do exception handling?
In my last project, which was in PHP, I designed the exception handling structure. I simply used exception classes. There were several exception classes like "ExternalException", "CallingFunctionException" and a few others. Based on this, a few other exception classes were based ("InvalidParameterException" on CallingFunction, "InvalidPermissionException" on External, etc). I think it was quite useful - since it could automatically find out which programmer should likely be responsible for fixing the problem quite nicely - but in general, this would be quite an overkill for C++ projects.
I could simply have one layer of exception classes, for every possible exception ("FileNotFoundException", "InvalidPermissionException", etc). On this method, a catch can easily be done for only several types that can be handled by the function.
For multiple exceptions, however, you have to override the constructor manually for every base class. So every exception takes a few lines (With eg. InvalidPermissionException(const char *what) : ExceptionBase(what) {}).
Some time ago I simply used a class that would be called like:
This made it possible to declare an extra exception really easy (class SomeException : public ExceptionBase {}).Code:Exception<InvalidPermissionException>::doThrow("Message here");
Another project, I simply made a "#define". I know they're considered evil in general, but again, I could simply declare an exception with a single macro, it would automatically create a class and add the constructor needed.
That's about the summary of my ideas. What do you guys think is the best method? Is there a better method than the ones I mentioned and if not, which method do you think is best?
Thanks,
EVOEx