【问题标题】:GDB. Catch only not caught exceptions广发银行。只捕获未捕获的异常
【发布时间】:2012-12-09 05:08:01
【问题描述】:

像这样捕获,使用 GDB

catch throw

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

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

catch throw

?

EDIT1

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

【问题讨论】:

  • 您能否详细说明您的意思?或者至少发布一些完整的代码?
  • 你没有使用 GDB catch throw
  • 很难理解catch throw部分是GDB命令。我建议你改写如“在 GDB 中使用命令 catch throw 时,...”
  • 抱歉误导。 EDIT2 为您服务

标签: c++ c gdb


【解决方案1】:

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

您在这里至少有两个选择。您根本不能使用catch throw,如果您使用某种unix,它会在抛出异常时进行seg fault并停止,如果它不会被捕获。

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

【讨论】:

  • 当什么都没有捕获时,是否有可能在 segfault 上看到回溯?
  • 是的,如果你没有捕捉到异常,gdb 应该在抛出点显示回溯。
猜你喜欢
  • 2010-09-28
  • 1970-01-01
  • 2012-05-31
  • 2014-05-11
相关资源
最近更新 更多