What is finally in Exception handling?

'finally' is a part of try-catch-throw and finally blocks for exception handling mechanism in Java.'finally' block contains snippet which is always executed irrespective of exception occurrence. The runtime system always executes the statements within the finally block regardless of what happens within the try block. The cleanup code is generally written in this part of snippet e.g. dangling references are collected here.


Anonymous said...

One point to add... if you call exit in try or catch, JVM will exit immediately without executing finally block.


Interview Questions On Java,Java EE Copyright © 2018. Reads: best tracker