7

I have an unhandled exception that causes the Exception Assistant dialog box to appear.

When I click on View Detail..., the exception itself has some values in it's custom object model that will not evaluate in the property grid, but I know I can evaluate it in the immediate window. (In this case the property grid won't let me drill down into a collection, but there can be other cases)

Without altering the code to add a try block, how can I go to the immediate window and evaluate expressions on the unhanded exception?

The answer will probably be some magic that I just don't know yet, like ?this.CurrentException or

something involving System.Diagnostics.StackFrame or who knows. Something clever.

There is a way to navigate to it using the debugger thread, but that's quite complicated. If you can take that and make it simple with a wrapper that might be a solution.

4

3 回答 3

11

您是否尝试将调试器设置为在引发异常时中断,而不是仅在用户未处理时中断?

为此,请转到 VS2010 主菜单并选择“调试”菜单,然后选择“异常...”

这将弹出一个对话框,如: 调试 -> 例外.. 菜单

选择抛出的列

现在,当您的异常被抛出并且您应该能够在立即窗口中评估您的局部变量。

在 Locals 选项卡中,我可以看到 $exception 变量: 局部变量包含 $exception

我可以在即时窗口中使用“$exception”变量: 访问 $exception 的立即窗口

更新: 另外,为了方便地切换异常处理,我建议使用Exception Breaker Visual Studio Extension,它允许您从工具栏打开和关闭异常处理的中断,而不必深入调试菜单。

于 2013-11-07T01:13:30.943 回答
1

我不了解 Visual Studio 2010,但在 Visual Studio 2012 中,当发生未处理的异常时,它会显示在Locals带有名称的窗口中$exception

于 2013-11-06T22:58:26.657 回答
0

有一个属性不会在属性网格中评估

如果无法评估该属性,调试器将无法为您提供帮助,如您所见;因此,即时窗口也会这样做。

我有一个无效属性,因此它会在 VS2010 中引发异常,并在我尝试评估它时导致调试器崩溃。从属性返回的 Null 对调试器来说并不好。

我建议您继续old school解决问题并将Trace.Write放在属性和其他地方,并在输出窗口中监视写入报告。

如何在 Visual C# 中进行跟踪和调试

于 2013-11-07T00:01:47.000 回答