How to set up Exception Policies and how to handle Exceptions

Topics: Exception Handling Application Block
Feb 9, 2007 at 6:41 AM
Edited Feb 9, 2007 at 6:44 AM
I created an application based on n-tier architecture. Now I want to integrate the Exception handling Application Block into this application.
My question is: what is the best practice for setting up the Exception Policies. I can't find any information about this subject.

My application architecture:

Presentation Layer
Business Layer
Data Layer

The requirements are:
- All exceptions will be logged
- In the Presentation Layer a default error message will be shown (ASP.NET, Windows Application or WebService) if unhandled

I think:
- exceptions must be logged where they occurs, because al technical details are available at that point.
- handle only exceptions I can handle, the remaining exceptions are unhandled and will cause an application shut down


Another question: in documentation the following code sample is used to explain how Exception Handling works. For example, how can I handle a DivideByZeroException Exception?

try
{
int amount = 100 / 0;
}
catch (Exception ex)
{
if (ExceptionPolicy.HandleException(ex, "Data Layer Policy"))
throw;
}

Imagine, 100/0 results in an DivideByZeroException. I know I can handle this situation by changing 0 into 1.
How can I code this handling code? Is the following code an appropriate manner?

int amount = 100;

try
{
amount = amount / 0;
}
catch (DivideByZeroException ex)
{
amount = amount / 1;
if (ExceptionPolicy.HandleException(ex, "Data Layer Policy"))
throw;
}

Could you help me?