#862 – Options for Including catch and finally Blocks

When you define a try block using the try keyword, you must also do one of the following:

  • Include one or more catch blocks after the try block
  • Include a finally block after the try block
  • Include one or more catch blocks after the try block, followed by a finally block

Whether you include a catch block, a finally block, or both, depends on what you want to accomplish:

  • Include catch blocks to intercept and act upon exceptions that got thrown as a result of executing the code in the try block.
  • Include a finally block if there are things that need to happen (like releasing resources), regardless of whether or not an exception occurs.
  • Include both catch and finally blocks if both statements above are true.

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #862 – Options for Including catch and finally Blocks

  1. Pingback: Dew Drop – June 10, 2013 (#1,564) | Alvin Ashcraft's Morning Dew

Leave a comment