Sending an Exception to the Exception Handling Application Block

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.

Interaction between application code and the Exception Handling Application Block occurs when the application code catches an exception and sends it to the application block to be handled. Application developers do not have to know how exceptions will be handled because they have to specify only the name of the relevant exception policy.

The following code shows how to pass exceptions of type DataAccessException to the Exception Handling Application Block. In the example, this causes a policy named Data Access Policy to be applied. The code checks the true or false value returned by the HandleException method. If the value is true, the original exception is rethrown. All other exception types are propagated back to the calling code.

try
{
  // Run code.
}
catch(DataAccessException ex)
{
  bool rethrow = ExceptionPolicy.HandleException(ex, "Data Access Policy");
  if (rethrow)
  {
    throw;
  }
}

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: