Exception Handling Application Block 為企業級應用程式各層級提供一致的例外處理方式,特點如下:
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", ex);
}
DataSet customersDataSet;
try
{
customersDataSet = RunQuery("GetAllCustomers");
}
catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Data Access Policy");
if (rethrow)
throw;
}
只需修改組態檔即可改變整個應用程式的例外處理行為,大幅降低維護成本。