$ exception is defined in "locals"

N We have a function of the log utility that we call quite often, and I wanted to revive it by adding a call to Server.GetLastError() , and if there is an error for logging in. The log function is part of a separate project, so I tried using HttpContext.Current.Server.GetLastError() (as well as for the Request, ServerVariables and Session properties). During testing, I created a simple exception:

  int i=0, j=0; try { int k = i / j; } catch (Exception E) { Tools.CooLog("in"); } Tools.CooLog("out"); 

To find out if "HttpContext.Current.Server.GetLastError ()" will throw an exception when calling Tools.CooLog("out"); .

Instead, I had two big surprises 1. Both calls to HttpContext.Current.Server.GetLastError() returned null. 2. And, perhaps, the strangest thing is that during the first call to CooLog in the locals section I saw a little of my young, beautiful and PHP version - I saw that there is a value called $ exception, and, surprisingly, the exception is HttpContext.Current.Server.GetLastError() failed to get!

$ exception is defined and HttpContext.Current.Server.GetLastError () fails

So my questions are 1. Why does HttpContext.Current.Server.GetLastError () return null? ( HttpContext.Current.Request.ServerVariables works fine) 2. Where does this $ exception come from? is there any way to use it? (in the second call to CooLog, the variable is undefined)

+7
source share
2 answers

This is a special debugger variable. You cannot access it through code.

The reason you don't see her in the Watch window is because this exception was:

  • Processed

or

  • The Application.Error event has not yet been fired.
+6
source

$exception is just an exception, because of which the debugger paused the execution of your program. This is the same as the exception you can get in your catch block, in your case E

+3
source

All Articles