Adding Application Code

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.

The Exception Handling Application Block is designed to support the most common scenarios for handling exceptions. When you add your application code, refer to the scenarios in Key Scenarios and select the ones that best suit your situation. Use the code that accompanies the scenario either as it is shown here or adapt it as needed.

To prepare your application to use the Exception Handling Application Block

  1. Add a reference to the Exception Handling Application Block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. Click the Browse tab, select the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll assembly, and then click OK.
  2. Following the same procedure, set a reference to the Enterprise Library core assemblies, Microsoft.Practices.EnterpriseLibrary.Common.dll and Microsoft.Practices.ObjectBuilder.dll. If you configure your application to use the Logging Exception Handler, set a reference to the required Logging Application Block assemblies. For information about the Logging Application Block assemblies, see the Logging Application Block documentation.
  3. (Optional) To use elements from the Exception Handling Application Block without fully qualifying the element reference, you can add the following using statement (C#) or Imports statement (Visual Basic) to the top of your source code file.
    using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
    
    
    Ff647919.note(en-us,PandP.10).gifNote:
    For Visual Basic projects, you can also use the References page of the Project Designer to manage references and imported namespaces. To access the References page, select a project node in Solution Explorer, and then click Properties on the Project menu. When the Project Designer appears, click the References tab.

Next, add the application code. Generally, code that uses the Exception Handling Application Block must complete the following steps:

  1. Catch an exception.
  2. Process an exception policy.
  3. Rethrow the original exception if that is what the policy recommends.

The scenarios in this section demonstrate how to incorporate these steps into an application.

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: