Problem in Application_Error

M

Michael

Using some example code I've found, I'm trying to do the custom error page
thing.

I have the following in global.asax..

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim oErr As System.Exception = Server.GetLastError()
Session("LastError") = oErr
End Sub

This throws an error and winds up back in Application_Error. When I get the
error using Server.GetLastError().GetBaseException() everything works as it
should, but the examples I've followed use GetBaseError() in the custom
error page code.

Can someone please explain this to me?

Thanks
 
K

Karl Seguin

Michael:
Are you simply asking what the difference between GetBaseException and
GetBaseError is? I don't know what GetBaseError is, it isn't part of the
framework and must be some custom implementatin that the example you saw
used....

Karl
 
M

Michael

My typo.. there is no GetBaseError, it should be GetBaseException().

The question is why does Session("LastError") =
Server.GetLastError().GetBaseException() work correctly and
Session("LastError") = Server.GetLastError() not work?
 
K

Karl Seguin

Michael:
By the time an exception gets to the Application_Error event, it's been
rebundled as an HttpUnhandledException. Server.GetLastError() will always
return an instance of HttpUnhandledException which really isn't what you
want. Server.GetLastError().GetBaseException() returns the actual exception
(the base exception) which initially caused the error.

In other words a level of indirection is created and this is just how you
get back the piece of information you are really after.

Karl
 
M

Michael

I understand now. Thanks Karl.


Karl Seguin said:
Michael:
By the time an exception gets to the Application_Error event, it's been
rebundled as an HttpUnhandledException. Server.GetLastError() will always
return an instance of HttpUnhandledException which really isn't what you
want. Server.GetLastError().GetBaseException() returns the actual exception
(the base exception) which initially caused the error.

In other words a level of indirection is created and this is just how you
get back the piece of information you are really after.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


works
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top