<exception>
terminate_handler set_terminate (terminate_handler f) throw();
Set terminate handler function
Sets
f as the
terminate handler function.
A
terminate handler function is a function automatically called when the exception handling process has to be abandoned for some reason. This happens when a handler cannot be found for a thrown exception, or for some other exceptional circumstance that makes impossible to continue the handling process.
The
terminate handler by default calls
cstdlib's
abort function.
Parameters
- f
- Function that takes no parameters and returns void.
The function shall not return and shall terminate the program.
terminate_handler is a function pointer type taking no parameters and returning void.
Return value
The current
terminate handler function.
terminate_handler is a function pointer type taking no parameters and returning
void.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| // set_terminate example#include <iostream>#include <exception>#include <cstdlib>using namespace std;void myterminate () { cerr << "terminate handler called\n"; abort(); // forces abnormal termination}int main (void) { set_terminate (myterminate); throw 0; // unhandled exception: calls terminate handler return 0;}
|
Possible output:
terminate handler calledAborted |
See also
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。