terminate( ), unexpected ( ), uncaught_exception( ) functions in C++

terminate( ) and unexpected ( ) functions: If there is any problem in the exception or error handling then terminate and unexpected are called. A header <exception> must be included to call these functions. A terminate function acts as a last process to avoid issues in an exception handling program. A terminate function automatically calls an abort() function. Terminate function is called when: 1) catch statement is missing; 2) program is rethrowing an exception when there was initially no exception thrown. Unexpected function is called when an unexpected throw happens in a program. Unexpected function automatically calls a terminate function.

Syntax of terminate:

void terminate( );

Syntax of unexpected:

void unexpected( );

uncaught_exception( ) function: It returns true when  throw has happened for an exception, but no catch statement is executed. Once catch is executed the function returns false.


bool uncaught_exception( );

Leave a Reply