Access Visual Studio's $exception variable

为君一笑 提交于 2020-04-18 06:04:41

问题


I have a situation where an onClose event Handler is running due to an exception thrown.

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. :(

  • The eventArgs of my eventHandler are just the Empty Event.
  • Asking Marshall.GetExceptionCode/Pointers() doesn't give me anything useful.

Evidently something knows about this exception, because VS can show it to me ... how can I get at that exception?


回答1:


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.

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



来源:https://stackoverflow.com/questions/59311634/access-visual-studios-exception-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!