Exception Handling Syntax

OverviewHow Do IFAQ

The structure for C++ exception handling is represented by the following syntax:

try-block :
   trycompound-statement handler-list

handler-list :
   handler handler-listopt

handler :
   catch ( exception-declaration ) compound-statement

exception-declaration :
   type-specifier-list declarator
   type-specifier-list abstract-declarator
   type-specifier-list
   ...

throw-expression :
   throwassignment-expressionopt

The compound-statement after the try clause is the guarded section of code. The throw-expression throws an exception. The compound-statement after the catch clause is the exception handler, and catches the exception thrown by the throw-expression. The exception-declaration statement after the catch clause indicates the type of exception the clause handles. The type can be any valid data type, including a C++ class.

If the exception-declaration statement is an ellipsis (...), the catch clause handles any type of exception, including C exceptions as well as system-generated and application-generated exceptions. This includes exceptions such as memory protection, divide-by-zero, and floating-point violations. An ellipsis catch handler must be the last handler for its try block.

The operand of throw is syntactically similar to the operand of a return statement.

Microsoft Specific —>

Microsoft C++ does not support the function exception specification mechanism, as described in section 15.4 of the ANSI C++ draft.

END Microsoft Specific