Export (0) Print
Expand All

Adding a New Exception Handler

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.

To add a new exception handler, you must first create a new class that implements the IExceptionHandler interface. After you compile the new class into an assembly, you can use the Enterprise Library Configuration Console to add it to the Exception Handling Application Block configuration for your application.

Creating a New Exception Handler Class

This procedure describes how to create a custom exception handler class. The code example shows a framework you can use as a basis for the class.

To create a new exception handler class

  1. Create a new class that implements the IExceptionHandler interface.
  2. Add the class attribute ConfigurationElementType. Specify the type CustomHandlerData as the attribute parameter.
  3. Implement the HandleException method. The HandleException method contains the exception handling logic for the custom handler. When the method completes, it returns an exception. This can be the same exception passed to the HandleException method or it can be a new exception created by your handler. The exception returned by the HandleException method passes to the next exception handler’s HandleException method.

The following is a skeletal custom handler class.

[ConfigurationElementType(typeof(CustomHandlerData))]
public class AppMessageExceptionHandler : IExceptionHandler
{
  public AppMessageExceptionHandler(NameValueCollection ignore)
  {
  }

  public Exception HandleException(Exception exception, Guid handlingInstanceId)
  {
     // Perform processing here. The exception returned will be passed to the next
     // exception handler in the chain. 
  }
}

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.
Show:
© 2014 Microsoft