Monday 26 March 2018

Does finally always execute in Java?

Yes, finally will be called.
The only times finally won't be called are:
  1. If you invoke System.exit();
  2. If the JVM crashes first;
  3. If there is an infinite loop (or some other non-interruptable, non-terminating statement) in the try block;
  4. If the OS forcibly terminates the JVM process.
  5. If the host system dies; e.g. power failure, hardware error, etc.

No comments:

Post a Comment