Propagating an Exception
A frequently required exception-handling task is to allow the original exception to propagate up the call stack unchanged. You may want to do this because the handlers only perform actions such as logging that leave the exception unchanged or because other actions, such as wrapping and replacing, have been turned off. For example, a routine within a business logic component may log exceptions at the point where they are detected. It then propagates that exception to the caller for additional handling.
You want to let an exception propagate up the call stack unchanged after the exception handler chain completes. Your application has code in its catch blocks similar to the following. The code does not include definitions of the FormatException and Logger.Log methods. These methods represent typical application code to create and log a formatted exception message.
The following procedure describes how to use the Exception Handling Block to propagate an exception.
To propagate an exception
- Create an exception handling policy with the relevant exception types for your application. For more information, see Entering Configuration Information.
- Configure the exception type. Specify the post-handling action as NotifyRethrow.
- Modify your application code to call the Process method to execute the target method, as shown here. This code assumes you have resolved an instance of the ExceptionManager class through the Enterprise Library container and saved it in a variable named exManager. Substitute the name of your own policy for "Propagate Policy." For more information on instantiating objects, see Creating and Referencing Enterprise Library Objects.
- Catch the exception in the appropriate section of your application code.