Server.GetLastError() doesn't show the actual line number of the error for Thrown exception
Posted on 2007-11-14
I'm using structured error handling in my ASP.NET app, so in Global.asax I have a
Dim ex As Exception = Server.GetLastError()
HttpContext.Current.Session("Exception") = ex
to redirect to an Error.aspx page which uses the session variable to handle the error.
This works fine for unhandled exceptions, but not if I explicitly Throw an exception. If I use
Catch ex As Exception
my Error.aspx, which uses the StackTrance of the session variable created in Application_Error, shows the line number of the Throw statement, and all the functions called prior to the one which generated the error, not the line number from that function that actually generated the error. I can write the exception to the console before the Throw statement and see the correct line number which generated the error, but how do I force this to show up in the GetLastError exception?