80 likes | 276 Views
C++ Exception Handling. C++ Exception Handling. Some Differences. No finally clause throw versus throws No root exception class Few C++ library routines throw exceptions. No finally clause. But all destructors will be invoked. See auto_ptr info. t hrow (C++) versus throws.
E N D
Some Differences • No finally clause • throw versus throws • No root exception class • Few C++ library routines throw exceptions
No finallyclause • But all destructors will be invoked. • See auto_ptr info
throw (C++) versus throws • No compile time checks of throw list • Missing throw list is allowed • Backward compatibility
No root exception class • Java Throwable objects contain a stack trace, but … • Little available from C++ exception object besides its type • Special syntax to catch all exceptions: • catch(. . .) will match any exception. • Good to use as the last catch in a group of catches. • Any object can be thrown in C++
Few C++ library routinesthrow exceptions • Rather, to signal errors they use • Return codes • Global variables • Object states
Other Considerations . . . • Exceptions should not be caught using call-by-value • Templates • Do not use throw list with any function template. • Inheritance • A handler for a base class exception can catch an exception object from a derived class.