Chapter 5. The Exception Handling Application Block


I WAS ONCE BROUGHT into a company to help them diagnose an issue they were having with one of their applications that had already been deployed to production. The Web application was redirecting users to the home page for every request. It was causing users a great deal of pain and the company was losing a lot of business. Upon investigation, I observed that the code shown in Listing 5.1 was smattered throughout the application.

Listing 5.1. Bad Example of Exception Handling

        Try         ...         Catch ex As Exception              Response.Redirect("welcome.aspx")         End Try

Exceptions were being caught and "swallowed" by the application. There was no notification or record of the actual issues that were occurring. The company lost several days of business while the application was malfunctioning, and the application frustrated many of the end users. I don't know how many dollars of business were lost; however, I do know that the consulting firm that developed the application was written off from ever doing business with that company again.

This is an example of what not to do when it comes to exception handling. Most developers understand that it is important to handle the exceptions that occur in an application; however, this example surfaces another point that may be less understood: It can often be worse to do exception handling wrong than not to do exception handling at all. The best solution is to handle exceptions in accordance with the best practices documented by the Microsoft patterns & practices team and highlighted in this chapter.

This chapter focuses on how to use Enterprise Library's Exception Handling Application Block (EHAB) so you can avoid scenarios like that shown in Listing 5.1. It describes how the design for the Exception Handling Application Block lets the way exceptions are handled and propagated through an application be expressed through configuration instead of code. It also shows how the application block has been designed for extensibility and provides examples for how to extend it.

The chapter goes into detail on how an enterprise can extend the Exception Handling Application Block with new ExceptionFormatters and ExceptionHandlers, because I believe it is important to understand that the Exception Handling Application Block does not constrain an enterprise from handling and formatting messages in the ways that best suit their needs. Lastly, it shows you how to configure and develop an application so you can benefit from the features provided by the Exception Handling Application Block.




Fenster Effective Use of Microsoft Enterprise Library(c) Building Blocks for Creating Enterprise Applications and Services 2006
Effective Use of Microsoft Enterprise Library: Building Blocks for Creating Enterprise Applications and Services
ISBN: 0321334213
EAN: 2147483647
Year: 2004
Pages: 103
Authors: Len Fenster

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net