H
We have log utility function that we call pretty often and I wanted to spice it up by adding a call to Server.GetLastError()
and if there is an error to log as well.
The log function is part of separate project so I tried to use HttpContext.Current.Server.GetLastError()
(As I do for the Request, ServerVariables and Session properties).
During the testing I created simple exception:
int i=0, j=0;
try
{
int k = i / j;
}
catch (Exception E)
{
Tools.CooLog("in");
}
Tools.CooLog("out");
In order to find out if "HttpContext.Current.Server.GetLastError()" will return the exception when Tools.CooLog("out");
is called.
Instead I had two big surprises
1. In both of the calls HttpContext.Current.Server.GetLastError()
returned null.
2. And maybe the weirdest is that during the first call of CooLog in the locals section I saw a bit of my young, handsome and PHP version - I saw that there is value called $exception and surprisingly it ha the exception that HttpContext.Current.Server.GetLastError()
failed to retrieve!
So my questions are
1. Why the HttpContext.Current.Server.GetLastError() returns null ? (HttpContext.Current.Request.ServerVariables
works fine)
2. Where that $exception comes from? is there a way to use it? (in the second call to CooLog the variable is undefined)
That is a special debugger variable. You cannot access it via code.
The reason you don't see it in the Watch window, is that the exception has either been:
or
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With