Exception Handling Block in n-Layer Architecture

Topics: Exception Handling Application Block, Logging Application Block
Dec 5, 2007 at 9:49 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 ;
}