C++核心文件中的异常信息
我有一个程序可以捕获未知异常。代码如下所示:
try {
...
} catch (...) {
abort(); // generates core file
}
我有一个核心文件和可执行文件。有没有办法让我知道它捕获了什么异常以及它在代码中的哪个位置生成,而无需重新编译或在 gdb 中再次运行? 我正在考虑尝试使用 gdb 从核心文件中找出所有这些。有什么想法如何做到这一点吗?
PS:我使用的是Linux CentOS 5.4
I have a program that catches unknown exception. The code looks like this:
try {
...
} catch (...) {
abort(); // generates core file
}
I have a core file and the executable. Is there any way for me to know what exception it caught and where in the code it was generated without recompiling or running again in gdb?
I was thinking about trying to figure out all this from the core file using gdb. Any ideas how to do that?
PS: I am on Linux CentOS 5.4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非您将回溯信息传递给异常(如此处所述) )并且除非捕获该异常,否则无法从抛出异常的位置获取信息。
由于 catch all (
catch(...)
) 块捕获了异常,因此您无法获取该信息。Unless you are passing the backtrace information to the exception (like explained here) and unless that exception is caught, there are no ways to get the information from where the exception is thrown.
Since the catch all (
catch(...)
) block caught an exception, you can not get that information.据我所知,您将无法获得异常已陷入 catch (...)
看看这篇文章:
如何获取catch-all异常的消息
As far as I know you won't be able to get wich exception has been trapped into a catch (...)
Look at this post:
how to get message of catch-all exception