std的terminate函数
来源:互联网 发布:招财猫是什么软件 编辑:程序博客网 时间:2024/05/17 22:57
原文: http://en.cppreference.com/w/cpp/error/terminate
本文翻译比较晦涩,可以只是大致了解下,也可以参考原文。
定义在<exception>中。
void terminate(); (until C++11)
[[noreturn]] void terminate(); (since C++11)
当异常处理因为以下原因失败时,std::terminate()就会在C++运行时被调用。
1) 一个异常被抛出但没有被捕获(由实现定义是否栈展开已经完成(implementation-defined whether any stack unwinding is done))。[译注: 关于栈展开(stack unwinding),可参见此篇博文]
2) 在异常处理过程中抛出异常(比如,来自于某本地对象的析构,或者来自于异常处理过程中必然要调用到的一个函数)。
3) 一个静态对象或线程本地对象的构造函数或析构函数抛出一个异常。
4) 使用std::atexit或std::at_quick_exit注册的函数抛出异常。
5) noexception规范被违反(由实现定义是否栈展开已经完成(implementation-defined whether any stack unwinding is done))。
6) dynamic exception规范被违反(由实现定义是否栈展开已经完成(implementation-defined whether any stack unwinding is done))。
7) std::unexpected的一个非默认handler抛出了一个异常,而这个异常违反了之前违反的dynamic exception规范,如果该规范没有包含std::bad_exception.
8) 如果std::nested_exception::rethrow_nested被一个并不hold所抓取到的异常的对象调用。
9) 一个异常被std::thread的初始化函数抛出。
10) 一个joinable的std::thread被销毁或被赋值给其他。(译注:关于joinable和detach,可参见此篇博文)
std::terminate也可能被程序直接调用。
在任何情况下,std::terminate会调用当前被安装的std::terminate_handler. 默认的std::terminate_handler是std::abort.
一个析构函数在栈展开(stack unwinding)的时候reset terminate handler,而栈展开后导致terminate被调用,那么在throw表达式的最后被安装的handler就是会被调用的handler. (注意,关于是否重新抛出被应用的新handler是有二义性的。)
本文翻译比较晦涩,可以只是大致了解下,也可以参考原文。
定义在<exception>中。
void terminate(); (until C++11)
[[noreturn]] void terminate(); (since C++11)
当异常处理因为以下原因失败时,std::terminate()就会在C++运行时被调用。
1) 一个异常被抛出但没有被捕获(由实现定义是否栈展开已经完成(implementation-defined whether any stack unwinding is done))。[译注: 关于栈展开(stack unwinding),可参见此篇博文]
2) 在异常处理过程中抛出异常(比如,来自于某本地对象的析构,或者来自于异常处理过程中必然要调用到的一个函数)。
3) 一个静态对象或线程本地对象的构造函数或析构函数抛出一个异常。
4) 使用std::atexit或std::at_quick_exit注册的函数抛出异常。
5) noexception规范被违反(由实现定义是否栈展开已经完成(implementation-defined whether any stack unwinding is done))。
6) dynamic exception规范被违反(由实现定义是否栈展开已经完成(implementation-defined whether any stack unwinding is done))。
7) std::unexpected的一个非默认handler抛出了一个异常,而这个异常违反了之前违反的dynamic exception规范,如果该规范没有包含std::bad_exception.
8) 如果std::nested_exception::rethrow_nested被一个并不hold所抓取到的异常的对象调用。
9) 一个异常被std::thread的初始化函数抛出。
10) 一个joinable的std::thread被销毁或被赋值给其他。(译注:关于joinable和detach,可参见此篇博文)
std::terminate也可能被程序直接调用。
在任何情况下,std::terminate会调用当前被安装的std::terminate_handler. 默认的std::terminate_handler是std::abort.
一个析构函数在栈展开(stack unwinding)的时候reset terminate handler,而栈展开后导致terminate被调用,那么在throw表达式的最后被安装的handler就是会被调用的handler. (注意,关于是否重新抛出被应用的新handler是有二义性的。)
1 0
- std的terminate函数
- 学习用于异常处理的terminate()函数
- 学习用于异常处理的terminate()函数
- 在roscore时出现 terminate called after throwing an instance of 'std::runtime_error'的解决方法
- erlang的terminate解析
- ubuntu12.04连接服务器的时候出现错误“terminate called after throwing an instance of 'std::runtime_error' what(”
- linux下的C++编程错误(一):terminate called after throwing an instance of ‘std::ios_base::failure' wha
- terminate
- std::string的工具函数
- std::string的工具函数
- std::string 的构造函数
- std::string的工具函数
- std::string的工具函数
- std::string的工具函数
- std::string的split函数
- std::string的工具函数
- std::string的工具函数
- std::string的工具函数
- c++中的顺序表写法,主要实现(增删查改,构造函数,运算符重载)
- c++中的双向链表写法,主要实现(增删查改,链表逆置,构造函数,运算符重载,等)
- 古典密码之hill密码的加密与解密程序实现
- 小明哥教你使用模板函数实现顺序表
- [C++] 利用模板的模板参数实现单链表
- std的terminate函数
- 注释转换小项目(c注释->到c++注释)
- 浅析《大数据运算》-加减乘除以及模除运算
- 初试->广义表
- 排序算法之插入排序
- 新手建站需要知道的一些知识
- hdu 5715 XOR 游戏(trie)
- 如何保证Service不被杀死一直运行
- 字符串指针变量