关于设置set_terminate函数

about setting up the set_terminate function

本文关键字:set terminate 函数 设置 于设置      更新时间:2023-10-16

我正在使用visual studio c++编译器,&在我学习异常处理的过程中,我遇到了很多visual c++编译器不支持的特性。比如控制可以从函数中抛出的异常。此外,我无法使用set_terminate()修改terminate()的功能。对于visual c++来说,修改terminate()也是一个规范吗?如果是这样,那么谁能解释一下为什么微软要在它的编译器中创建这些规范?

你说你无法修改终止是什么意思

你试过这样做吗?

// set_terminate example
#include <iostream>
#include <exception>
#include <cstdlib>
using namespace std;
void myterminate () {
  cerr << "terminate handler calledn";
  abort();  // forces abnormal termination
}
int main (void) {
  set_terminate (myterminate);
  throw 0;  // unhandled exception: calls terminate handler
  return 0;
}

不要尝试从VS.运行,从命令行编译并执行