C++ throw()引发的core
来源:互联网 发布:淘宝集运香港仓电话 编辑:程序博客网 时间:2024/05/29 05:56
总结最近遇到了一个问题,简单说就是一个禁止抛出异常的函数内抛出了异常所致(无论函数内部直接抛出异常还是间接调用函数抛出异常)
官方文档说明如下:
If this throw
specifier is left empty with no type, this means that std::unexpected is called for any exception. Functions with no throw
specifier (regular functions) never call std::unexpected, but follow the normal path of looking for their exception handler.
12
int myfunction (int param) throw(); // all exceptions call unexpectedint myfunction (int param); // normal exception handling
即一个throw()的函数意味着对任何异常调用std::unexpected
而std::unexpected函数的官方文档说明如下:
By default, the unexpected handler calls terminate. But this behavior can be redefined by calling set_unexpected.
This function is automatically called when a function throws an exception that is not listed in its dynamic-exception-specifier (i.e., in its throw
specifier).
This function is provided so that the unexpected handler can be explicitly called by a program, and works even ifset_unexpected has not been used to set a custom unexpected handler (calling terminate in this case).
即该函数默认为调用terminate函数
而terminate函数的说明如下:
By default, the terminate handler calls abort. But this behavior can be redefined by calling set_terminate.
This function is automatically called when no catch
handler can be found for a thrown exception, or for some other exceptional circumstance that makes impossible to continue the exception handling process.
This function is provided so that the terminate handler can be explicitly called by a program that needs to abnormally terminate, and works even if set_terminate has not been used to set a custom terminate handler (callingabort in this case).
即该函数默认调用abort函数
故一个throw为空的函数内部有任何异常抛出的效果是导致程序调用abort。
简单的代码示例如下:
voidfunc2() { //一个抛出异常的函数
throw 2;
}
void func1() throw() { //一个禁止抛出异常的函数
func2();
}
int main(int argc, char ** argv) {
func1();
return 0;
}
运行结果:
- C++ throw()引发的core
- c#: throw和throw ex的区别
- std::sort引发的core
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- C数据类型引发的安全隐患
- 【C++】指针引发的bug
- php打印warning日志引发的core追查
- php打印warning日志引发的core追查
- “log4net.Core.LoggerManager”的类型初始值设定项引发异常
- c++throw类型
- c++primer throw char*
- 一道C面试题引发的思考
- 写一个函数,检查字符是否是整数,如果是,返回其整数值。(或者:怎样只用4行代码编写出一个从字符串到长整形的函数?)
- 网络和计应12级电子商务学习
- 《Java核心技术》复习笔记 - 第六章 接口与内部类
- 【选择排序】堆排序--Java
- C语言经典算法100例-021-猴子吃桃问题
- C++ throw()引发的core
- Cookie深度解析
- 《Java核心技术》复习笔记 - 第十三章 集合
- STM32学习心得
- java中TextArea和JTextArea的自动换行和滚动条
- 《Java核心技术》复习笔记 - 第十四章 多线程
- linux下通过ssh登陆失败解决方案
- js 禁止 ctrl 缩放
- SQLite数据库操作详细示例