像这样捕捉,使用 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/