Reputation: 35679
I'm just starting to use the Enterprise Library Exception Handling block.
It seems a little cumbersome.
Do I really have to do
try
{
//Do something with a DirectoryInfo object
}
catch(DirectoryNotFoundException ex)
{
bool rethrow = ExceptionPolicy.Handle(ex, _exceptionPolicyName);
if(rethrow)
throw;
}
Everywhere I want to handle exceptions?
Or should I just wrap the top level in
try
{
//Entrypoint code
}
catch(Exception ex)
{
bool rethrow = ExceptionPolicy.Handle(ex, _exceptionPolicyName);
if(rethrow)
throw;
}
I was under the impression I could aspect this on with attributes?
Upvotes: 1
Views: 759
Reputation: 161773
How many places do you need to handle exceptions?
This Application Block is mainly used for handling exceptions on the boundaries of layers. For instance, the top-level code of your Data Access Layer might use this so you can configure whether and how to log DAL exceptions, whether to wrap a non-DAL exception, etc. But your private, inner methods should not handle exceptions at all.
And no, EAL doesn't do attributes.
Upvotes: 2