用GDB中更有意义的错误描述替换SIGABRT
Replacing SIGABRT with more meaningful description of error in GDB
当我在gdb调试器中执行反向跟踪(bt)时,它显示程序接收到信号SIGABRT, Aborted.
在我写的c++程序中,我只写了throw;
是否有一种方法可以用更有意义的错误描述替换SIGABRT ?
像index out of bound error
,甚至index 15 exceeds the bounds of the array with shape (2, 3, 4).
我不认为改变信号是可能的,但是如果你想在gdb中看到一个更有用的错误消息,你总是可以抛出一个特定的异常:
void do_something(){
throw std::out_of_range ("This is a very specific message.");
}
在gdb中显示如下:
(gdb) r
Starting program: /home/pascal/code/exception-test
terminate called after throwing an instance of 'std::out_of_range'
what(): This is a very specific message.
Program received signal SIGABRT, Aborted.
0x00007ffff753c035 in raise () from /lib/x86_64-linux-gnu/libc.so.6
您可以在这里找到可能的异常列表:http://en.cppreference.com/w/cpp/error/exception
相关文章:
- 模板参数替换失败,并且未完成隐式转换
- 如何用转义符替换字符串中的所有特殊字符
- 使用VerQueryValue检索应用程序的文件描述
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 如何在C/C++中用FD_set Unix设置套接字文件描述符
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- 在一个读写器队列中,我可以用volatile替换原子吗
- 用符号版本替换对函数的所有调用
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 如何通过替换顺序代码的while循环来添加OpenMP for循环
- 替换基于地图的所有引用
- 从 Boost ASIO 获取 epoll 描述符 io_service对象
- 按平均值替换数组中的元素
- 我可以在这里替换什么,因为我不能在 C# 中使用隐式变量的 lambda 函数?
- 如何将字节数组元素替换为修改的十六进制 ASCII 符号?
- 初始化 std::vector 替换为单大括号而不是双大括号
- 删除/替换C++字符串中的多字符 (ÿû)
- 在C++标准中,它在哪里指示用它所代表的源代码替换类别描述符的间隔协议
- 是否有 gcc 或 makefile 的机制可以描述源文件的包含文件以替换 #include "xxxx.h"?
- 用GDB中更有意义的错误描述替换SIGABRT