G
Guest
First let me say that I understand that Asp.Net wraps my exception in an
HttpUnhandledException. I have found a lot of discussion about that on the
web, which was informative, but not helpful. Let me explain how my question
is different.
Second, let me say that I have two questions. One is an ASP.Net related
question. The other is a general System.Exception question. They are related
but also individual.
Okay here is my problem...
I have an ADO wrapper library. I use it to wrap provider-specific exceptions
with my own. For example when a opening a connection fails, my library has
its own exception that it throws. Consumers of my library don't know if it
was an Oracle connection that failed, an SqlClient connection that failed,
etc. However just in case, I do put the original ADO provider's exception in
the *innerException* property of my library's exception.
When an exception is thrown by my library, and not handled in the aspx page,
IIS displays the default error screen, which is fine. But it displays the
*inner-most* exception. So in this case, instead of displaying my library's
exception, it displays the provider's exception, which I had put into my
library's exception's innerException property. This is not what I want. I
don't want consumers of my library to see the provider exception unless they
really want to.
Like I said at the top of my post, I understand that it would not display
the outer-most exception. That would be the HttpUnhandledException. But I
don't understand why it drills down to the inner-most exception.
So I started poking around...
I stopped populating my library's exception's innerException. Now IIS
displayed my exception just like I wanted. When there is no innerException,
IIS displays my exception.
I wondered if there was something special about the provider exception that
made IIS want to display it, instead of displaying mine. So I populated my
library's exception's innerException with a new dummy exception. IIS still
displayed the inner-most exception.
Feeling frustrated I wondered if GetBaseException was being called. So I
overrode it. *Success!* If I return a new dummy exception from my library's
overridden GetBaseException method, that is what shows up in IIS. So clearly,
yes, IIS is showing the inner-most exception.
Why does IIS take it upon itself to decide that the inner-most exception
should be displayed? This makes me mad. Why would I wrap one exception inside
another if I don't want the outer exception to be exposed to the world? I
fully understand that IIS does not want to display the outer-most exception
(the httpUnhandledException).
Thinking, I override GetBaseException to return "me" (c# syntax "this"). It
doesn't work. I'm not sure what is going on. When I am not sure what is going
on I always turn to my trust friend the .Net Reflector!
(http://www.aisto.com/roeder/dotnet/). Sure enough take a look at this little
method known as System.Exception.GetBaseException()...
Public Overridable Function GetBaseException() As Exception
Dim exception1 As Exception = Me.InnerException
Dim exception2 As Exception = Me
Do While (Not exception1 Is Nothing)
exception2 = exception1
exception1 = exception1.InnerException
Loop
Return exception2
End Function
Notice anything funny? It does *not* call the innerExceptions's
GetBaseException. It just starts drilling down on *it's own* through the
InnerExceptions directly. Why doesn't it call the InnerException's
GetBaseException? That wouldn't be recursion exactly, but it would make more
sense to me. As it stands, overriding GetBaseException only works when you
are the outer-most exception. If the overriding exception gets wrapped up as
an inner exception (say for example in an HttpUnhandledException, as in this
case) all your precious overridden GetBaseException logic is *out the window*.
So I have two questions...
1) Why does IIS display the GetBaseException of the HttpUnhandledException
instead of the InnerException?
2) Why does System.Exception.GetBaseException drill down on its own through
the InnerExceptions, instead of honoring the possibly overridden
GetBaseExceptions?
Any information, education, guidance, or I-feel-your-pains would be greatly
appreciated.
John DeHope
HttpUnhandledException. I have found a lot of discussion about that on the
web, which was informative, but not helpful. Let me explain how my question
is different.
Second, let me say that I have two questions. One is an ASP.Net related
question. The other is a general System.Exception question. They are related
but also individual.
Okay here is my problem...
I have an ADO wrapper library. I use it to wrap provider-specific exceptions
with my own. For example when a opening a connection fails, my library has
its own exception that it throws. Consumers of my library don't know if it
was an Oracle connection that failed, an SqlClient connection that failed,
etc. However just in case, I do put the original ADO provider's exception in
the *innerException* property of my library's exception.
When an exception is thrown by my library, and not handled in the aspx page,
IIS displays the default error screen, which is fine. But it displays the
*inner-most* exception. So in this case, instead of displaying my library's
exception, it displays the provider's exception, which I had put into my
library's exception's innerException property. This is not what I want. I
don't want consumers of my library to see the provider exception unless they
really want to.
Like I said at the top of my post, I understand that it would not display
the outer-most exception. That would be the HttpUnhandledException. But I
don't understand why it drills down to the inner-most exception.
So I started poking around...
I stopped populating my library's exception's innerException. Now IIS
displayed my exception just like I wanted. When there is no innerException,
IIS displays my exception.
I wondered if there was something special about the provider exception that
made IIS want to display it, instead of displaying mine. So I populated my
library's exception's innerException with a new dummy exception. IIS still
displayed the inner-most exception.
Feeling frustrated I wondered if GetBaseException was being called. So I
overrode it. *Success!* If I return a new dummy exception from my library's
overridden GetBaseException method, that is what shows up in IIS. So clearly,
yes, IIS is showing the inner-most exception.
Why does IIS take it upon itself to decide that the inner-most exception
should be displayed? This makes me mad. Why would I wrap one exception inside
another if I don't want the outer exception to be exposed to the world? I
fully understand that IIS does not want to display the outer-most exception
(the httpUnhandledException).
Thinking, I override GetBaseException to return "me" (c# syntax "this"). It
doesn't work. I'm not sure what is going on. When I am not sure what is going
on I always turn to my trust friend the .Net Reflector!
(http://www.aisto.com/roeder/dotnet/). Sure enough take a look at this little
method known as System.Exception.GetBaseException()...
Public Overridable Function GetBaseException() As Exception
Dim exception1 As Exception = Me.InnerException
Dim exception2 As Exception = Me
Do While (Not exception1 Is Nothing)
exception2 = exception1
exception1 = exception1.InnerException
Loop
Return exception2
End Function
Notice anything funny? It does *not* call the innerExceptions's
GetBaseException. It just starts drilling down on *it's own* through the
InnerExceptions directly. Why doesn't it call the InnerException's
GetBaseException? That wouldn't be recursion exactly, but it would make more
sense to me. As it stands, overriding GetBaseException only works when you
are the outer-most exception. If the overriding exception gets wrapped up as
an inner exception (say for example in an HttpUnhandledException, as in this
case) all your precious overridden GetBaseException logic is *out the window*.
So I have two questions...
1) Why does IIS display the GetBaseException of the HttpUnhandledException
instead of the InnerException?
2) Why does System.Exception.GetBaseException drill down on its own through
the InnerExceptions, instead of honoring the possibly overridden
GetBaseExceptions?
Any information, education, guidance, or I-feel-your-pains would be greatly
appreciated.
John DeHope