throw"Help!";
can be caught by a
handler
of
constchar*
type:
try{// ...}catch(constchar* p){// handle character string exceptions here}
and
class Overflow {public:
Overflow(char,double,double);
};
void f(double x){throw Overflow('+',x,3.45e107);
}
can be caught by a handler for exceptions of type
Overflow:
try{
f(1.2);
}catch(Overflow& oo){// handle exceptions of type Overflow here}
When an exception is thrown, control is transferred to the nearest handler with
a matching type ([except.handle]); “nearest” means the handler
for which the
compound-statement or
ctor-initializer
following the
try
keyword was most recently entered by the thread of control and not yet exited.
If the type of the exception object would be
an incomplete type,
an abstract class type ([class.abstract]),
or a pointer to an incomplete type other than cvvoid
the program is ill-formed.
when an active handler for the exception exits by
any means other than
rethrowing,
immediately after the destruction of the object (if any)
declared in the exception-declaration in the handler;
A thrown exception does not
propagate to other threads unless caught, stored, and rethrown using
appropriate library functions; see [propagation] and [futures].
When the thrown object is a class object, the constructor selected for
the copy-initialization as well as the constructor selected for
a copy-initialization considering the thrown object as an lvalue
shall be non-deleted and accessible, even if the copy/move operation is
elided ([class.copy.elision]).
The destructor is potentially invoked ([class.dtor]).
If the exception handling mechanism
handling an uncaught exception
directly invokes a function that exits via an
exception, the function std::terminate is invoked.
[Example 2: struct C {
C(){}
C(const C&){if(std::uncaught_exceptions()){throw0; // throw during copy to handler's exception-declaration object ([except.handle])}}};
int main(){try{throw C(); // calls std::terminate if construction of the handler's// exception-declaration object is not elided ([class.copy.elision])}catch(C){}} — end example]