How Does Try Catch Finally Work

The finally -block contains statements to execute after the try -block and catch -block(s) execute, but before the statements following the try… … The code opens a file and then executes statements that use the file; the finally -block makes sure the file always closes after it is used even if an exception was thrown.

Can you have a try catch in a finally?

A try-finally block is possible without catch block. Which means a try block can be used with finally without having a catch block.

How try catch finally works internally in Java?

  1. If the finally block completes normally, then the try statement completes normally.
  2. If the finally block completes abruptly for reason S, then the try statement completes abruptly for reason S.
Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest