set_unexpected
Installs your own termination function to be called by unexpected.
typedefvoid(*unexpected_function)();
unexpected_functionset_unexpected(unexpected_functionunexp_func**);**
Routine | Required Header | Compatibility |
set_unexpected | <eh.h> | ANSI, Win 95, Win NT |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB | Single thread static library, retail version |
LIBCMT.LIB | Multithread static library, retail version |
MSVCRT.LIB | Import library for MSVCRT.DLL, retail version |
Return Value
_set_unexpected returns a pointer to the previous termination function registered by _set_unexpected, so that the previous function can be restored later. If no previous function has been set, the return value may be used to restore the default behavior; this value may be NULL.
Parameter
unexp_func
Pointer to a function that you write to replace the unexpected function
Remarks
The set_unexpected function installs unexp_func as the function called by unexpected. unexpected is not used in the current C++ exception-handling implementation. The unexpected_function type is defined in EH.H as a pointer to a user-defined unexpected function, unexp_func, that returns void. Your custom unexp_func function should not return to its caller.
By default, unexpected calls terminate. You can change this default behavior by writing your own termination function and calling set_unexpected with the name of your function as its argument. unexpected calls the last function given as an argument to set_unexpected.
Unlike the custom termination function installed by a call to set_terminate, an exception can be thrown from within unexp_func.
In a multithreaded environment, unexpected functions are maintained separately for each thread. Each new thread needs to install its own unexpected function. Thus, each thread is in charge of its own unexpected handling.
In the current Microsoft implementation of C++ exception handling, unexpected calls terminate by default and is never called by the exception-handling run-time library. There is no particular advantage to calling unexpected rather than terminate.
See Also abort, set_terminate, terminate, unexpected