Walkthrough: Propagating the Original Exception

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.

This walkthrough demonstrates the steps to enable the original exception to propagate. Figure 1 illustrates the process.

Ff647113.3d7919d7-eb0e-4b47-a5bb-1e2cbbf74dcf(en-us,PandP.10).png

Figure 1
Propagating the original exception

The QuickStart executable calls a method in the business layer assembly, and an exception occurs. The Exception Handling Application Block uses the specified policy—Propagate Policy—to handle the exception. This policy is configured to handle exceptions of type System.Exception and has a PostHandlingAction set to NotifyRethrow. This causes the call to the HandleException method to return true to the business layer.

When the business layer detects that the return value is true, it rethrows the original exception. The QuickStart executable catches this exception and calls ProcessUnhandledException. This routine calls HandleException and passes the policy named Global Policy. This policy is configured to run a custom exception handler that displays a dialog box that contains the exception message.

To reproduce this scenario

  1. Create a new blank solution in Visual Studio.
  2. Add a Windows-based application project named ExceptionHandlingBasicQuickStart to the solution.
  3. Add a class library project named ExceptionHandlingQuickStart.BusinessLayer to the solution.
  4. Rename the class in ExceptionHandlingQuickStart.BusinessLayer to AppService.
  5. Add the ProcessA and ProcessWithPropagate methods to the AppService class. These methods are included in the QuickStart source code.
  6. Use the configuration tools to create a new application configuration file.
  7. Use the configuration tools to add the Exception Handling Application Block to the application configuration file.
  8. Add a new exception policy named Propagate Policy.
  9. Add the exception type System.Exception to Propagate Policy.
  10. Configure the System.Exception exception type to have a PostHandlingAction of NotifyRethrow.