Enterprise Library 2.0--Exception handing applcation block

Source: Internet
Author: User

The Exception handing applcation block in Enterprise Library 2.0 provides a consistent way for our developers and designers to handle the anomalies at every level of our entire enterprise application, as shown in the following areas:

1, it provides an exception handling method for each layer of the architecture of the application, and is not only limited to the service layer interface;

2. Provide common exception handling methods, such as recording exception information, using our custom exception information to replace the system's exception information and so on;

3, we can define the rules of exception handling, and can not modify the code to modify the exception handling rules;

4, it supports our developers to create their own exception handling methods;

5, the same method to invoke the exception handling method, which makes exception handling can be used anywhere in the application.

When we do exception handling, we generally adopt a strategy:

1, packaging

2. Replace

3, log

So, Exception handing application block can give us the benefit of development? First look at the following code:

DataSet customersDataSet;

try
{
 customersDataSet = RunQuery("GetAllCustomers");
}
catch(Exception ex)
{
 string formattedInfo = FormatException(ex);
 Logging.Log(formattedInfo);
 throw new DataAccessException("Database access failure for query GetAllCustomers",e);
}

The code above estimates that we are the most familiar, yes, such code in our application is expected to run through every corner of our program, but when we change the way we handle the exception, we have to modify all the code, which is a very depressing thing, Exception The appearance of handing application block has solved the problem for us, after using the exception handing application block, we only need to modify the configuration file to change all the exception handling methods in the application. As follows:

DataSet customersDataSet;

try
{
 customersDataSet = RunQuery("GetAllCustomers");
}
catch(Exception ex)
{
 bool rethrow = ExceptionPolicy.HandleException(ex, "Data Access Policy");
 if (rethrow)
  throw;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.