Explain 'try','catch' and 'finally' blocks?

In Java exceptions are handled in try, catch, throw and finally blocks. It says try a block of Java code for a set of exception/s catch an exception if it appears in a catch block of code separate from normal execution of code. It clearly segregates errors from a block of code in an effective and efficient manner. The exceptions, which are caught, thrown using throw keyword. A finally block is called in order to execute clean up activities for any mess caused during abnormal execution of program.


Poke said...

Regarding the finally block, it is not exclusive to catching exceptions...it is run whether the try block completed successfully or generated an exception caught in the catch block. It should contain any code that needs to run regardless of whether the try block succeeds or fails.


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