|Microsoft Enterprise Library 5.0|
|Designing for Encapsulation of Behavior in Reusable Handlers|
The Exception Handling Application Block helps developers to create exception handlers that represent common exception handling tasks. These handlers, as well as combinations of handlers, can be used by different policies.
Encapsulating exception-handling behavior into reusable handlers implies two things about the block's design:
- There must be a common interface that the handlers implement.
- Policies must be able to support ordered combinations of handlers.
The next section describes each of these implications.
Application components use a policy name and an exception to indicate to the Exception Handling Application Block the behavior to be performed. The block provides this behavior by executing the exception handlers configured for the policy. To allow the block to correctly execute the handlers, all handlers must implement the IExceptionHandler interface. The three handlers provided by the block all support this interface, but developers can easily write custom handlers that conform to the same interface.
Policy Support for Ordered Combinations of Exception Handlers
Exception handlers can be reused across policies because they typically address single tasks. They can be combined within an exception policy to address more complex tasks. The policy executes the configured handlers in order.