Exception Handling Application Block

 

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

Exception Handling Application Block

patterns & practices Developer Center

Enterprise Library for .NET Framework 1.1

patterns & practices Developer Center

Microsoft Corporation

June 2005

Summary

This page provides an overview of the Enterprise Library Exception Handling Application Block. This is reusable and extensible source code-based guidance that simplifies development of common exception handling functionality in .NET-based applications.

Downloads
License
Hands-On Labs
Webcasts
Community

* Important Note: The January 2005 release of Enterprise Library is no longer available to download, due to important issues discovered after the release. Customers building new applications should move to the June 2005 release. Customers who have already adopted the January release must apply the patches available on Enterprise Library Community site. Please direct any questions to the community site or to devfdbck@microsoft.com

Contents

Introduction to the Exception Handling Application Block
Design of the Exception Handling Application Block
Test Drive
Feedback and Support
June 2005 Release Updates
Roadmap
Authors and Contributors
Related Titles

Introduction to the Exception Handling Application Block

The Enterprise Library Exception Handling Application Block lets developers and policy makers create a consistent strategy for processing exceptions that occur throughout the architectural layers of enterprise applications. It does this in the following ways:

  • It supports exception handling throughout an application's architectural layers and is not limited to service interface boundaries.
  • It enables exception-handling policies to be defined and maintained at the administrative level so that policy makers, who may be system administrators as well as developers, can define how to handle exceptions. They can maintain and modify the sets of rules that govern exception handling without changing the block's application code.
  • It provides commonly used exception-handling functions, such as the ability to log exception information, the ability to hide sensitive information by replacing the original exception with another exception, and the ability to add contextual information to an exception by wrapping the original exception inside another exception. These functions are encapsulated in .NET classes named exception handlers.
  • It can combine exception handlers to produce the desired response to an exception, such as logging exception information followed by replacing the original exception with another.
  • It lets developers create their own exception handlers.
  • It invokes exception handlers in a consistent manner. This means that the handlers can be used in multiple places in and across applications.

Common Scenarios

The Exception Handling Application Block is designed to support the typical code contained in catch statements in application components. Instead of repeating this code (such as logging exception information) throughout identical catch blocks in an application component, the application block allows developers to encapsulate this logic as reusable exception handlers. Exception handlers are .NET classes that encapsulate exception handling logic and implement the Exception Handling Application Block interface named IExceptionHandler. The Exception Handling Application Block includes three exception handlers:

  • Wrap handler. This exception handler wraps one exception around another.
  • Replace handler. This exception handler replaces one exception with another.
  • Logging handler. This exception handler formats exception information, such as the message and the stack trace. Then the logging handler gives this information to the Enterprise Library Logging and Instrumentation Application Block so that it can be published.

The Exception Handling Application Block lets you associate exception types with named policies. You do this using the Configuration Console. Policies specify the exception handlers that execute when a particular exception type is processed by the application block. You can chain these handlers together so that a series of them execute when the associated exception type is handled.

Audience Requirements

This application block is intended for software architects and software developers. To benefit fully from this guidance, you should have an understanding of the following technologies:

  • Microsoft Visual C# development tool or Microsoft Visual Basic development system
  • .NET Framework

Highlights of the Enterprise Library Exception Handling Application Block

The Enterprise Library Exception Handling Application Block includes the following new features:

  • A graphical tool for managing configuration settings
  • A broad set of tools for developing exception handling policies
  • The ability to define and maintain exception-handling policies at the administrative level
  • Commonly used exception-handling functions

Migrating from the Exception Management Application Block

The earlier version of the application block, named the Exception Management Application Block, was used to publish exception information to particular locations. The new application block, named the Exception Handling Application Block, provides a broader set of tools for developing exception handling strategies. There are three major differences between the Exception Handling Application Block and the Exception Management Application Block:

  • The task of publishing exception information is no longer integrated with other exception handling tasks. Instead, it is handled specifically by the logging handler. The logging handler formats the information and hands it off to the Logging and Instrumentation Application Block to publish the information.
  • Exception handlers can be chained together, with each handler having the ability to execute before the exception that is delivered to subsequent handlers in the chain.
  • The Exception Management Application Block operated only on the original exception that was passed to it by the application and it could only log the exception information. The Exception Handling Application Block provides a much broader set of abilities. It can change, suppress, or add information to the exception and replaces most of the code typically found in an application's catch statements.

System Requirements

To develop application blocks using the Exception Handling Application Block you need following:

  • Microsoft Windows 2000, Windows XP Professional, or Windows Server 2003 operating system
  • Microsoft .NET Framework 1.1
  • Microsoft Visual Studio .NET 2003

Exception Handling Application Block Dependencies

The application blocks that are provided with the Enterprise Library are designed to be used in conjunction with each other. Sometimes, the application blocks have dependencies on other application blocks and code that is included with the Enterprise Library. The Exception Handling Application Block has the following dependencies:

  • The Enterprise Library Configuration Application Block. The Exception Handling Application Block uses this to read its configuration information.
  • Common library functionality, such as instrumentation. This provides various functions for exposing events and data used for system management.

The application block includes an exception handler that logs exception information. Applications that use this logging exception handler require the Logging and Instrumentation Application Block.

By default the application block uses XML files to store configuration information. The recommended way to modify this information is to use the Enterprise Library Configuration Console.

Design of the Exception Handling Application Block

The Exception Handling Application Block is designed to achieve the following goals:

  • To encapsulate the logic used to perform the most common exception handling tasks into minimal application code
  • To relieve developers of the requirement to write duplicate code and custom code for common exception handling tasks
  • To allow exception handling policies to be changed after they have been deployed and to ensure that changes happen simultaneously and consistently
  • To incorporate best practices for exception handling

Design Highlights

Figure 1 shows the interrelationships between the key classes in the Exception Handling Application Block.

Ff648029.f01entlib04(en-us,PandP.10).gif

Figure 1. Design of the Exception Handling Application Block

Test Drive

The Exception Handling Application Block has been developed as a result of analyzing common enterprise development challenges and successful solutions to these challenges. However, because each application is unique, you will not find this application block suitable for every application. To evaluate this application block and determine its applicability to your projects, Microsoft suggests you dedicate at least half of a day to explore the application block. The following is a suggested evaluation approach:

  1. Download Enterprise Library.
  2. Install Enterprise Library and compile all application blocks and tools.
  3. Read the "Introduction" and "Scenarios and Goals" sections of the documentation.
  4. Compile and run the QuickStart samples, and read through the related "QuickStart Walkthroughs" and "Key Scenarios" sections of the documentation.
  5. If the application block looks like a good fit for your application, try implementing a simple use case in your application or in a throw-away prototype application using the application block.

Feedback and Support

Questions? Comments? Suggestions? To provide feedback about this application block, or to get help with any problems, please visit the Enterprise Library Community site. The community site is the preferred feedback and support channel because it allows you to share your ideas, questions, and solutions with the entire community. Alternatively, you can send e-mail directly to the Microsoft patterns & practices team at devfdbck@microsoft.com, although we are unable to respond to every message.

Enterprise Library is a guidance offering, designed to be reused, customized, and extended. It is not a Microsoft product. Code-based guidance is shipped "as is" and without warranties. Customers can obtain support through Microsoft Support Services for a fee, but the code is considered user-written by Microsoft support staff. For more information on our support policy, see the Enterprise Library home page

June 2005 Release Updates

The June 2005 release of Enterprise Library is a minor update of the original version released in January 2005. Please see About the June 2005 Release for more information on the updates to the application blocks for the June 2005 release.

Roadmap

An updated release of the Exception Handling Application Block is planned for the next release of Enterprise Library. This release will target the .NET Framework 2.0 and Visual Studio 2005 and will include additional improvements based on customer feedback.

Authors and Contributors

The Enterprise Library Exception Handling Application Block was produced by the following people:

  • Program Managers: William Loeffler (Microsoft Corporation), Linh Nguyen (Avanade Inc)
  • Product Manager: Tom Hollander (Microsoft Corporation)
  • Architects: Edward Jezierski (Microsoft Corporation), Kyle Huntley (Avanade Inc)
  • Development: Scott Densmore, Peter Provost (Microsoft Corporation), Brian Button (Murphy and Associates), Timothy Shakarian (Avanade Inc)
  • Test: Mohammad Al-Sabt, Carlos Farre (Microsoft Corporation), Mani Krishnaswami, Gokulaprakash Thilagar, Rohit Sharma, Prashant Bansode, Jeevarani Radhakrishnan, Dhananjaya Rao (Infosys Technologies Ltd), Pavan Kumar Sura (Volt)
  • Documentation and Samples: RoAnn Corbisier (Microsoft Corporation), Tim Osborn (Ascentium Corporation), Roberta Leibovitz (Modeled Computation LLC), Paul Slater (Wadeware LLC), Tina Burden McGrayne (Linda Werner & Associates Inc)

Many thanks to the following advisors who provided invaluable assistance:

  • Rudy Araujo, Yen-Ming Chen, Mark Curphey and David Raphael of Foundstone Inc.
  • Benoit Morneau and Shoichi Takasaki of Bowne Global Solutions

Start | Previous | Next

patterns & practices Developer Center

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.