c++ - GDB。只捕获未捕获的异常

标签 c++ c gdb

像这样捕捉,使用 GDB:

catch throw

当抛出异常时,程序停止。

如何让GDB在抛出异常但被程序捕获时不停止? 或者我应该使用全局 try-catch 而不是使用 GDB

catch throw

?

编辑1

try
{
  // every time exception is thrown
  // program is stopped by GDB
}
catch(const std::exception &e)
{
  // even if the exception is caught by the program
}

EDIT2 启动 gdb

gdb
file /usr/home/user/program
shell ps x
attach #pid
catch throw
c

最佳答案

catch throw 将捕获所有抛出的异常,并且没有办法限制它。

您在这里至少有两个选择。您可以根本不使用 catch throw,如果您使用的是 unix 的某种风格,它会在抛出异常时出现段错误并停止,如果它不会被捕获的话。

或者,您可以在 __raise_exception 上设置断点,如 ftp://ftp.gnu.org/pub/old-gnu/Manuals/gdb/html_node/gdb_30.html 所示(这是我使用谷歌时的第一个点击 - 请在 Stackoverflow 上发帖之前尝试研究自己)。

关于c++ - GDB。只捕获未捕获的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13784828/

相关文章:

c - 在 C 中伪造寄存器读取

c - Process Coredumped 但看起来不像多线程程序中的非法引用

c++ - 奇怪的 C 堆栈内存覆盖

C++ 线程不工作, "error: ' 线程'不是 'std' 的成员“

c++ - 如何追踪 LLVM verifyFunction 错误 "Expected no forward declarations!"?

c - 知道是否使用了 const 限定符

c++ - 为什么 GDB "next"两次显示构造函数行?

c++ - 为什么 sizeof 给我这个结果?

c++ - C++ 中的 OpenCV 整数除法不符合预期

c - C中简单平均计算的错误值输出