V
Vladimir Ciobanu
Ekim said:hy,
I've a question concerning exception-handling in c++:
is there a possibility to catch any exception (I know one can do
that by
"catch(...)") and display its default-error-message (like in Java)?
or do you have to create your own exceptions and make your own
error-messages?
No, there isn't. You can only catch an exception if you know its type,
or you
can use the "catch(...)" form. Exceptions are made to postpone error
handling
up to a point where there's enough information to do something
meaningful.
I would only need the error-number or something like a short
description
which exception occured, and subsequently I want to write it to a
logfile.
Therefore I want to log every exception, and not a specific
exception I had
to define beforehand.
Ok, I'll admit. If the exceptions have a common base class, you can
catch them
by a reference to that class (and all the standard exceptions derive
from
std::exception). However, note that if there are user-defined
exceptions that don't
have std::exceptions as a base class, your catch( std::exception& e )
won't match.
Vladimir Ciobanu