分享

set-terminate

 WUCANADA 2011-12-03

set_terminate

function
<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 called
Aborted

See also

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多