Tuesday, August 07, 2007 2:04 PM
kolbis
Creating a custom exception handler
With enterprise library 3.1 you can create a custom exception handler that will handle the exception on hand.
First you need to create a custom exception handler. In order to implement your custom handler you must follow 3 rules:
- Implement the IExceptionHandler.
- Add a class attribute that implements the ExceptionHandlerData (e.g. CustomExceptionData).
- Add a constructor that receives a NameValueCollection.
Here is a sample ExceptionHandler that implements those 3 rules:
[ConfigurationElementType(typeof(CustomHandlerData))]
public class MyCustomHandler : IExceptionHandler
{
public MyCustomHandler(NameValueCollection collection)
{
}
#region IExceptionHandler Members
public Exception HandleException(Exception exception, Guid handlingInstanceId)
{
return new ApplicationException(exception.Message, exception);
}
#endregion
}
After you created your implementation of a custom exception handler, you need to define the Custom handler in the Enterprise Library configuration tool.
Select your assembly that contains the custom handler class.

That is it, you are set to use it.
תגים:Enterprise Library 3.1