本文介绍了如何使用gdb获取C ++中当前异常的值和类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gdb允许在抛出异常时捕获它们,当它们被捕获时。但有时抛出异常的行没有符号,或者在异常处理期间触发断点。如何检查当前异常的值?

解决方案

已更新






以下是GDB手册中的一些信息






p>

这取决于代码和堆栈中的位置。如果你实际上遇到了例外:

  try {....} catch(std :: exception& e) {
//做东西
}

你可能会尝试打印code> e.what(),或查看异常的成员。如果你只是把它当作(...),那么我不知道你能收集什么。



你可以做的另一个处理方法是抓住如果你真的想跟随整个流程,那么'g'中的'throw'也可以捕捉'catch'。

  gdb> catch catch 
gdb> catch throw

这样你就可以在异常被抛出之前得到一个断点,然后您可以走栈来获取有关发生的更多信息。即使你处于另一个断点,你应该能够走上栈(使用向上或向下)来获得异常可见的框架。


gdb allows one to catch exceptions when they're thrown, and when they're caught. But sometimes the line an exception is thrown has no symbols, or a breakpoint is triggered during exception handling. How do I inspect the value of the current exception?

解决方案

Updated


Here's some info from the GDB Manual


That said

It depends on the code and where you are in the stack. If you actually caught the exception as in :

try { .... } catch (std::exception &e) {
   //do stuff
}

You could probably try printing e.what(), or look at the members of the exception. If you just caught it as (...) then I'm not sure what you'd be able to gather.

Another handling thing you could do is to catch 'throw' in gdb and catch 'catch' as well if you really want to follow the whole flow.

gdb> catch catch
gdb> catch throw

This way you will get a breakpoints right before exceptions are thrown and right as they are caught, you could then walk the stack to gain more information about what was going on. Even if you are in another break point you should be able to walk up the stack (using up or down) to get the frame in which the exception is visible.

这篇关于如何使用gdb获取C ++中当前异常的值和类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:54
查看更多