Tech Off Post

Single Post Permalink

View Thread: Doing the same thing for multiple exception types
  • User profile image

    The first and last forms are the best.  The middle one is actually different from the VB one. 

    The key here is the the difference between catches, finally's, and filters and when they run.  There are two passes to exception handling (  The catch runs on the 2nd pass, but the filter (the when clause in VB) runs on the 1st pass - that's also where finally's run.  Catching an exception (interrupting the 1st pass) and rethrowing is generally considered bad.  For example you interrupt the debugging experience and you raise a 2nd exception (and exceptions aren't cheap).  There's probably other reasons out there as well.

    So 1 or 3, never 2.