Thursday, March 22, 2012

Server.GetLastError()

I am using Server.GetLastError() to get error details for logging, which is fine, but what I really need is the actual line of code that caused the error.

If you don't have a custom error page, it shows you the actual line that caused the error but I can't seem to find it in the Server.GetLastError() object.

I have noticed that the following code gets me the name of the procedure in which the error occurred:
appException = Server.GetLastError()
MsgBox(appException.TargetSite.Name)

But not the actual line of code that triggered the error.Look at the properties of the exception named SOURCE, MESSAGE, STACKTRACE.
I have. They don't give me what I need.
Sorry, I haven't been able to find anything for this. It seems like the line-of-code that's erroring out is something that the framework keeps to itself, for security purposes? :confused:
Oh dear...:(
One thing to make sure of:

Did you compile the Application to DEBUG and no RELEASE? Lines of code are not available in release compiles. Also, make sure that the PDB file got uploaded. This is the debug trace hook file.

All that said, it is entirely possible it will not keep the line number around because you have to execute this code (Server.GetLastError()) AFTER the page exception occurs and is thrown, which has probably cleared the exception stack already.

0 comments:

Post a Comment