Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 2(e)

2 marks

Computer ScienceISC 2018 Computer Science Paper 1Short answerStatements, Scope

Answer the following.

What is exceptional handling? Also, state the purpose of finally block in a try catch statement.

Answer

Answer

Exception handling is a mechanism in Java to detect and handle runtime errors (exceptions) - abnormal conditions that disrupt the normal flow of a program's execution (e.g. division by zero, array index out of bounds) - using the keywords try, catch, throw, throws and finally, so that the program can respond to the error gracefully instead of terminating abruptly. Purpose of the finally block: The finally block contains code (such as closing files/releasing resources) that must always be executed, whether or not an exception occurs in the try block and whether or not it is caught by a catch block. It is used for essential clean-up code that must run under all circumstances.