An exception is an unexpected event or error that occurs during the execution of a program, often due to incorrect input, resource unavailability, or logical errors. Exceptions disrupt the normal flow of the program, but they can be handled using special blocks of code.
Two common exception handling blocks are:
(i) try-catch Block: This block is used to catch and handle exceptions that occur in the code within the try block. The catch block contains the code to handle the exception.
(ii) finally Block: The finally block is used to execute important code, such as resource cleanup, regardless of whether an exception occurs or not.
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.