Posts

Java exception handling interview questions

Image
1. What Is an Exception in Java? An exception is an event that occurs during the execution of a program and disrupts the normal flow of the program's instructions. 2. How Does Exception Handling Work in Java? Below steps demonstrates how the exception handling works in Java: Step 1:  When an error occurs within a method, the method creates an object and hands it off to the runtime system this object is called an  exception object . The exception object contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called  throwing an exception . Step 2:  After a method throws an exception, the runtime system attempts to find something to handle it. The set of possible "somethings" to handle the exception is the ordered list of methods that had been called to get to the method where the error occurred. The list of methods is known as the  call st