抛出异常时获取堆栈跟踪

抛出异常时获取堆栈跟踪

问题描述:

我现在正在调试一个使用许多不同线程的程序。

I am now debugging a program that utilizes many different threads.

有一个例外是不时抛出的。问题是没有办法知道什么线程导致了问题...

there is an exception that is thrown from time to time. the problem is that there is no way to know what thread caused the problem...

有没有人知道一个简单的方法来获取堆栈跟踪在抛出异常之后?我想到只是编写一个调试消息,但它将是一个巨大的:-)我想有比这更好的技术...

does anyone know an easy way to get the stack trace after the exception is thrown? I thought about simply writing a debug messages but it is going to be a huge :-) i guess there are much better techniques than this one ...

我是使用visual studio 2008 - native c ++ project ....

I'm using visual studio 2008 - native c++ project....

除非我非常错误,否则需要知道哪个线程触发了异常,以便使用Visual Studio调试器的调用堆栈视图,这显然是您目前所处的catch-22状态。

Unless I'm very much mistaken, you need to know which thread triggered the exception in order to use the Visual Studio debugger's call stack view, which is obviously the catch-22 situation you're in at the moment.

有一件事尝试是看是否可以让调试器在异常抛出时中断(使用Debug> Exceptions)。你必须明确地启用这个,但是如果你知道抛出什么类型的异常,这可能会让你找出抛出的地方。

One thing I would try is to see if you can get the debugger to break when the exception is thrown (using Debug > Exceptions). You'll have to explicitly enable this, but if you know what type of exception is thrown, this might allow you to work out where it's thrown.

除此之外,在异常的构造函数中放置一个断点(如果是自己的构造函数)也应该允许你解决从哪个引发的地方。

Other than that, putting a breakpoint in the constructor of the exception (if it's one of your own) should also allow you to work out where it's triggered from.

如果这些方法不为您工作,我将按照您建议的方式查看调试消息。

If those methods don't work for you I'd be looking at the debug messages as you already suggested.