ASP.net 2.0 & Exception Handling Block

Topics: Exception Handling Application Block
Mar 27, 2007 at 6:02 PM
Has anyone leveraged the January 2006 Exception Handling Block with an ASP.Net 2.0 web project? Everything is dandy until I change my debug config setting to false. Once I do that (Which is how it must be in Production) when calling bool rethrow = ExceptionPolicy.HandleException(LobjError, "AS2ArchivePolicy"); Is there a dependency for this method on debug being set to true for the application. I basically just log exception.

I receive the following Message

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@ Page Language="C#" Debug="true" %>
Mar 27, 2007 at 11:23 PM
I don't quite understand the problem. It sounds like you get an exception when you turn off debugging. Can you post the exception?

Regards,

Dave

__________________________

David Hayden
Microsoft MVP C#
Mar 28, 2007 at 1:53 AM
Hello David,

Thanks for your time. Basically in the Global.asax file in the OnApplication error event I do a server transfer to a custom exception page. In this page if Debug=true, I basically display error information in page otherwise if Debug=false I try to call the HandleException method with a polcicy that simply logs the error to the application log. Issue is once I compile with no debug symbols it complains using the ASP.NEt error page:

"The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@ Page Language="C#" Debug="true" %>"

Bascially seems that the Application block is dependent on the debug symbols. If I comment out the one call to the Exception policy the custom error page is displayed as expected. I googled this issue for hours but did not find any similar posts. Again, thanks for your time.
Mar 28, 2007 at 3:11 AM
Hi Christopher,

You might want to re-think your process if I am understanding you correctly. Once you get to the global exception handler your application is essentially shutting down. The Exception Handling Block is really meant to be used to evaluate exceptions before you get to that point.

I would just log the error from within the error handler. I have a quick tutorial here:

Enterprise Library 2.0 Logging Application Block Part II - Simple ASP.NET 2.0 Website Example - Logging Unhandled Exceptions

You don't need to transfer to a custom error page. I don't even know if that is allowed and will have to try it. You normally specify a custom error page in your web.config that will be invoked automatically:

<customErrors mode="On" defaultRedirect="YourErrorPage.htm" />

I will have to spend some more time seeing what is allowed and not allowed when the global exception handler is invoked, but as a rule of thumb, you don't want to get fancy in there. At that point in the application you have probably ruled out the expected problems and are dealing with an unknown. You usually don't want to do anymore than log the error and display a custom error page.

Hopefully this helps.

Regards,

Dave

_________________________

David Hayden
Microsoft MVP C#