7.2. Catching an Exception

We catch exception objects by their type using one or a series of catch clauses. A catch clause consists of three parts: the keyword catch, the declaration of a single type or single object within parentheses, and a set of statements within curly braces that does the actual handling of the exception. For example, consider the following set of catch clauses:

 // defined elsewhere ... extern void log_message( const char* ); extern string err_messages[]; exterm ostream log_file; bool some_function() { bool status = true; // ... we'll get to this part! catch( int errno ){ log_message( err_messages[ errno] ); status = false; } catch( const char *str ){ log_message( str ); status = false; } catch( iterator_overflow &iof ...

Get Essential C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.