is there a good general policy for setting up the sequence of catch blocks?
views:
37answers:
2
+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
2009-06-01 03:19:28
WOuld there be a performance hit with more than 1 catches?
2009-06-01 03:21:32
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
2009-06-01 03:23:36
+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
2009-06-01 03:21:30