Partilhar via


Design of the Exception Handling Application Block

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

  • Encapsulate the logic used to perform the most common exception handling tasks into minimal application code.
  • Relieve developers of the requirement to write duplicate code and custom code for common exception handling tasks.
  • Allow exception handling policies to be changed after they have been deployed and to ensure that changes happen simultaneously and consistently.
  • Incorporate best practices for exception handling, as described in the Design Guidelines for Exceptions.

Design Highlights

The following schematic shows the interrelationships between the key classes in the Exception Handling Application Block.

Ff664763.2684555d-5a45-41c0-8ee8-a4d767219dea(en-us,PandP.50).png

Client code interacts with the Exception Handling Application Block by calling the HandleException or Process method of the ExceptionManager class. The ExceptionManager creates an object of type ExceptionManagerImpl for the named policy. The ExceptionManagerImpl object has a collection of ExceptionPolicyEntry objects. There is one object for each exception type that is specified in the configuration file for the named policy. For each exception type, the ExceptionPolicyEntry object contains a collection of objects that implements the IExceptionHandler interface. The collection is ordered and provides the sequence that the Exception Handling Application Block uses when executing the policy. Each object that implements the IExceptionHandler interface has associated configuration information that is specific to each type of handler.

For more information about the design of the block, see Designing for Simplified Catch Blocks and Designing for Encapsulation of Behavior in Reusable Handlers.