
In .NET applications, an illegal operation - an invalid cast, attempting to reference a null value, trying to connect to a database
that's been taken offline, and so on - raises an exception. Exceptions can be caught and handled directly in code
through the use of Try / Catch blocks. For ASP.NET applications, if the exception is
not handled in code, it bubbles up to the ASP.NET runtime, which raises an HttpUnhandledException.
By default, unhandled exceptions result in a page that displays the text, "Runtime Error" with instructions for developers on how to display exception details
(see the screen shot to the right). This "Runtime Error" error page is what is seen by external visitors; if you visit your site through
localhost and an unhandled exception occurs, the default error page includes the type and details of the exception thrown.
[View a screenshot]
End users will no doubt find the "Runtime Error" page to be intimidating and confusing - do you think the average computer
user knows what "Runtime" means? All the user knows is that something went horribly wrong. They might fear
that their data or progress has been lost and that they are responsible for the error. Ironically, the person who does care
that an unhandled exception has occurred - the developer - is left out of the loop unless the end user takes the time to
email the developer the details of the error (what page it happened on, the steps the user had performed that caused the
error, and so on).
Fortunately, ASP.NET provides solutions to these two problems. An ASP.NET application
can be configured to automatically redirect the user to a less-intimidating page that explains that there has been a problem.
This custom, user-friendly error page can omit such lingo like "Runtime" and have its look and feel match the website's.
Additionally, there are techniques available to log and alert the developer of the unhandled exception.
In this article we'll look at how to display user-friendly error pages in the event of an unhandled exception.
A future article will examine how to log and alert the site administrator when such exceptions occur. Read on to learn more!
Read More >