问题
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