-
A try block must use braces {} and has its own scope.
-
A try block must be followed by one or more catch blocks.
-
A catch block must use braces {} and is a scope.
-
Each catch block must have a declaration list
-
Declaration lists declare one type, with an optional identifier.
-
The catch block can treat the identifier like a local variable.
|
-
catch block identifiers shadow other local variables.
-
It is possible to catch *any* exception:
void f()
{
try
{
acct.withdraw( 2000000 );
}
catch ( ... )
{
// free dynamic memory:
delete[] my_temp_array;
throw;
}
}
|