views:

37

answers:

2

is there a good general policy for setting up the sequence of catch blocks?

+1  A: 

I would catch the most "specific" exception first, then further down catch the more general ones:

try {
  ...
}
catch (DivideByZeroException ex) {
 ...
}
catch (InvalidArgumentException ex) {
  ...
}
catch (Exception ex) {
  ...
}
John Rasch
WOuld there be a performance hit with more than 1 catches?
Technically yes, but there would not be a relevant performance hit. I wouldn't worry about this though, since optimizing error scenarios hardly seems worth the time :)
John Rasch
+1  A: 

Here are some design guidelines from MSDN. It might also be good to check out the Enterprise Library exception handling block. Lots of good stuff there for architecting an exception handling strategy.

JP Alioto
+1 - Good link even for non-.NET languages
John Rasch