问题描述
我有一种情况,由于抛出异常,正在运行 onClose
事件处理程序。
I have a situation where an onClose
event Handler is running due to an exception thrown.
如果我强制它在附加了VS调试器的情况下发生,那么我可以在VS'Locals'中看到一个 $ exception
局部变量,该变量具有(一些)有趣的信息。
If I force it to happen with the VS debugger attached, then I can see in VS 'Locals' a $exception
local variable, which has (somewhat) interesting information on it.
但是我不知道如何在代码中获取该异常,以便我可以对其进行记录。 :(
But I can't figure out how to get at that exception within the code, so that I can log it. :(
- 我的eventHandler的eventArgs只是
Empty
事件。 - 问
Marshall.GetExceptionCode / Pointers()
没给我任何帮助。
- The eventArgs of my eventHandler are just the
Empty
Event. - Asking
Marshall.GetExceptionCode/Pointers()
doesn't give me anything useful.
很明显有人知道此异常,因为VS可以向我显示此异常...我该如何获得该异常?
Evidently something knows about this exception, because VS can show it to me ... how can I get at that exception?
推荐答案
您真正想要的功能不存在,VS神奇地捕获了当前异常并将其放在 $ exception
伪变量中
The capability you really want doesn't exist. VS magically grabs the current exception and puts it in the $exception
pseudo variable in order to make your debugging experience better.
在$codeatch中唯一可以访问(在代码中)的地方块,如果要捕获它,则需要在此处完成VS调试器为您提供了更多伪变量:
The only place you have access (in your code) to it in in a catch
block. If you want to capture it, you need to do it there. There are a bunch more pseudo-variables the VS debugger makes available to you: https://docs.microsoft.com/en-us/visualstudio/debugger/pseudovariables?view=vs-2019
这篇关于访问Visual Studio的$ exception变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!