Just sharing some of my inconsequential lunch conversations with you... RSS  

Wednesday, August 01, 2007

Mapping SQL Server Errors to .NET Exceptions (the fun way!)

Tom Hollander has just posted about mapping SQL Server Errors to .NET Exceptions, where he ends up with the following code and statement:

 try
{
Database db = DatabaseFactory.CreateDatabase("MyDatabase");
db.ExecuteNonQuery("spMySproc", param1, param2);
}

catch (Exception ex)
{

if (ExceptionPolicy.HandleException(ex, "Data Access Policy"))

throw;

}

This is a lot nicer, but it still requires that the boilerplate exception logic is included in every data access method. But with the magic of the Policy Injection Application Block, you don't even need to do this. By configuring a policy in the PIAB configuration, or decorating your data access class or individual methods with the [ExceptionCallHandler] attribute, you can get the desired behavior with no exception handling logic in the code at all!


No comments:

Development Catharsis :: Copyright 2006 Mário Romano