In C++, unlike .NET or Java, there is no one single parent exception class for all cases. You cannot catch all exceptions by your code. The seeming similarity of
CException
with such universal base exception types is misleading; it's nothing like that.
To catch all exceptions, you would need to write something like this:
try{
} catch (SomeConcreteExceptionType * e) {
} catch (SomeOtherConcreteExceptionType * e) {
} catch (...) {
}
Many developers said,
catch (...)
is bad style, but I disagree. Bad style is abusing anything, including this catch method, but there are number of cases when this is absolutely needed. One example: the very top stack frame of all threads.
What is really bad is your idea to catch exception in your function at all. You should catch exceptions in as little points as possible. You should simply "let go". Out of your function, anywhere. Catch exceptions only on the top stack frame and, in same rare cases, in some special points. Exceptions are not "errors". Exception are designed to isolate handling of special situations from "normal" execution flow. If you try to catch exceptions here and there, you totally defeat the purpose of the technology.
Please see also my past answer:
Unhandled Exception : Access Violation[
^].
—SA