Information Technology Reference
In-Depth Information
ReportGenericError(e);
throw ;
}
finally
{
CleanupResources();
}
Different catch clauses can exist for different runtime types of exceptions.
Yo u , a s a n a p p l i c a t i o n a u t h o r, m u s t c r e a t e o r u s e d i f f e r e n t e x c e p t i o n c l a s s e s
when catch clauses might take different actions. Note that every different
exception above is handled in a different way. Developers only want to
provide different catch clauses for different exception classes when the
handling is different. Otherwise, it's just extra work. Therefore, you should
consider creating different exception classes only when you believe devel-
opers will take different actions for the problems that cause the exception.
If you don't, your users are left with only unappealing options. You can punt
and terminate the application whenever an exception gets thrown. That's
certainly less work, but it won't win kudos from users. Or, they can reach
into the exception to try to determine whether the error can be corrected:
private static void SampleTwo()
{
try
{
Foo();
Bar();
}
catch ( Exception e)
{
switch (e.TargetSite.Name)
{
case "Foo" :
FixProblem(e);
break ;
case "Bar" :
ReportErrorAndContinue(e);
break ;
// some routine called by Foo or Bar:
default :
ReportErrorAndShutdown(e);
Search WWH ::




Custom Search