Header Ads

  • Breaking Now

    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.

    1 comment:

    1. 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.

      ReplyDelete

    Post Top Ad

    Post Bottom Ad