Share via


The Effects of the Exception Handler

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 GetCustomerName method of the business object checks for an empty value passed as the customer ID property and throws an ArgumentNullException containing the message, "This exception will be replaced...". The exception handler defined in the policy for the GetCustomerName method replaces this exception with a new Exception instance that contains a more informative message describing the problem. This requires only configuration of the Policy Injection Application Block and Exception Handling Application Block; it does not require any changes to the application code. Figure 1 illustrates the result.

Ff649139.be3bd5f3-c838-4aa5-baa9-1b31587938df(en-us,PandP.10).png

Figure 1
The exception handler replaces the ArgumentNullException with a new exception

The ability to capture, wrap, ignore, or replace exceptions raised by code provides a technique to hide information that you may not want available in exceptions, add more informative messages and resolution information, and integrate applications with monitoring environments. With the Policy Injection Application Block, you can set this up and modify it during deployment and operation without changing the application code. It is still necessary to restart the application for updated policies defined in configuration to take effect.