/// If you write a replacement %terminate handler, it must be of this type.
typedef void (*terminate_handler) ();
/// If you write a replacement %unexpected handler, it must be of this type.
typedef void (*unexpected_handler) ();
/// Takea a new handler function as an argument, return the old function.
terminate_handler set_terminate(terminate_handler) throw();
/** The runtime will call this function if %exception handler must be
* abandoned for ayn reason. It can also be called by the user. */
void terminate() __attribute__ ((_noreturn__));
/// Takea a new handler function as an argument, return the old function.
unexpected_handler set_unexpected(unexpected_handler) throw();
/** The runtime will call this function if an %exception is thrown which
* violates the function's %exception specification. */
void unexpected() __attribute__ ((_noreturn__));
/** [18.9.4]/1: "Returns true after completing evaluation of a
* throw-expression until either completing initialization of the
* exception-declaration in the matching handler or entering @c unexcepted()
* due to the throw; or after entering @c terminate() for any reason
* other than an explicit call to @c terminate(). [Note: This includes
* stack unwinding [15.2]. end note]"
* 2. "When @c uncaught_exception() is true, throwing an %exception can
* result in a call of @c terminate() (15.5.1)"
*/
bool uncaught_exception() throw();
try{
...
} catch(...) {}
Here, the ellipsis "..." is alike the ellipsis at the macro in scheme language. It just is a wild-card.
int thwfun() throw(EA, EB, EC, ED, EE, EF);
try{
thwfun();
} catch(EA) {};
catch(EB) {};
catch(...) {};
Now, the ellipsis "..." means to match EC, ED, EE, EF, or nothing match if the thwfun() throw() defined.
If an exception thrown is out of the throw list, the unexpected_handler() will be set off. An uncaught
exception will set off terminated_handler() whether not unexpected_handler() was called. Note, the uncaught_exception()
will return true before setting off terminated_handler().
throw an exception;
bool uncaught_exception(){
if ( the thrown exception is not in throwing list ) {
unexpected_handler();
return true;
}
if ( the thrown exception does not match any catch handler ) {
return true;
}
return false;
}
if ( uncaught_exception() == true ){
terminate_handler();
}
typedef void (*terminate_handler) ();
/// If you write a replacement %unexpected handler, it must be of this type.
typedef void (*unexpected_handler) ();
/// Takea a new handler function as an argument, return the old function.
terminate_handler set_terminate(terminate_handler) throw();
/** The runtime will call this function if %exception handler must be
* abandoned for ayn reason. It can also be called by the user. */
void terminate() __attribute__ ((_noreturn__));
/// Takea a new handler function as an argument, return the old function.
unexpected_handler set_unexpected(unexpected_handler) throw();
/** The runtime will call this function if an %exception is thrown which
* violates the function's %exception specification. */
void unexpected() __attribute__ ((_noreturn__));
/** [18.9.4]/1: "Returns true after completing evaluation of a
* throw-expression until either completing initialization of the
* exception-declaration in the matching handler or entering @c unexcepted()
* due to the throw; or after entering @c terminate() for any reason
* other than an explicit call to @c terminate(). [Note: This includes
* stack unwinding [15.2]. end note]"
* 2. "When @c uncaught_exception() is true, throwing an %exception can
* result in a call of @c terminate() (15.5.1)"
*/
bool uncaught_exception() throw();
try{
...
} catch(...) {}
Here, the ellipsis "..." is alike the ellipsis at the macro in scheme language. It just is a wild-card.
int thwfun() throw(EA, EB, EC, ED, EE, EF);
try{
thwfun();
} catch(EA) {};
catch(EB) {};
catch(...) {};
Now, the ellipsis "..." means to match EC, ED, EE, EF, or nothing match if the thwfun() throw() defined.
If an exception thrown is out of the throw list, the unexpected_handler() will be set off. An uncaught
exception will set off terminated_handler() whether not unexpected_handler() was called. Note, the uncaught_exception()
will return true before setting off terminated_handler().
throw an exception;
bool uncaught_exception(){
if ( the thrown exception is not in throwing list ) {
unexpected_handler();
return true;
}
if ( the thrown exception does not match any catch handler ) {
return true;
}
return false;
}
if ( uncaught_exception() == true ){
terminate_handler();
}