‹ Back to the paper
What is exceptional handling? Also, state the purpose of finally block in a try catch statement.
Answer
Answer
AIException 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.
From ISC 2018 Computer Science Paper 1, question 2(e).