Exception Handling Block in n-Layer Architecture

Topics: Exception Handling Application Block, Logging Application Block
Dec 5, 2007 at 10:16 AM
Exception Handling Block in Layer Architecture.

Data Access Layer

Try
{

}

catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "DataAccess Layer Policy");
if (rethrow)
{
throw;

}
}

Business Logic Layer:

Try
{
}
catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Business Layer Policy");
if (rethrow)
{
throw;

}
return false;
}





In Data Access Layer Policy I gave all exception type for particular layer.


I want to use which syntax. whether Syntax-1 or Syntax-2

Syntax - 1

catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Business Layer Policy");
if (rethrow)
{
throw;
}


}

syntax 2

catch (SQLException ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Business Layer Policy");
if (rethrow)
{
throw;

}


}

Data Access Policy : I will refer all types of exceptions, but here I have one doubt , this Exception Handle Block automatically takes hirechary of exceptions or not.

means:
********************************


catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Business Layer Policy");
if (rethrow)
{
throw;
}


}

In web.config , Business Layer Policy i given all types of exceptions. still i am confuge which syntax to use .


try
{

}
catch (ArgumentNullException ex)
{
throw ;
}
catch (NullReferenceExceptiondata ex)
{
throw ;
}
catch (Exception exception)
{
throw ;
}
Dec 5, 2007 at 4:07 PM
Edited Dec 5, 2007 at 4:25 PM
Test
Dec 5, 2007 at 4:46 PM
Exception Policy does take care of hierarchy, So, if you are sure you have added all the types that you need handle, in the policy, and you don't have any other defensive code to be written in catch blocks, you can always use only one generic exception catch block. Entlib policy will take care of executing right ExceptionType in the exception policy. It is a coding standards thing.

- Neo.
Dec 6, 2007 at 3:28 AM
Edited Dec 6, 2007 at 4:29 AM
Thank you very much