#863 – How a finally Block Works with No catch Block

When you include a finally block with some code that’s surrounded by a try block, you’re saying that you want the code in the finally block to run after the code in the try block, whether or not an exception occurs.

If no exception occurs while executing the statements in the try block, the statements in the finally block simply execute after the code in the try block.

If an exception does occur and you have a finally block, but no catch block, the following happens:

  • Some of the code in the try block executes, up to the point where the exception occurred
  • The code in the finally block executes
  • The exception continues bubbling up the call stack
  • Code in the current method that’s located after the finally block does not execute
Advertisement

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: