Java Exception Handling Interview Questions and Answers
Experienced / Expert level questions & answers
Ques 1. What is the difference between 'finally' block and 'final' keyword?
'finally' is used in exception handling to define a block of code that will be executed whether an exception is thrown or not. 'final' is a keyword used to apply restrictions on class, method, and variable.
Ques 2. Explain the concept of 'suppressed exceptions' in Java.
Suppressed exceptions are exceptions that are not propagated up the call stack and are associated with try-with-resources. They are added to the primary exception as suppressed exceptions.
Ques 3. How can you handle exceptions in a multi-threaded environment?
You can use try-catch blocks inside the run() method of a thread or implement the 'Thread.UncaughtExceptionHandler' interface.
Ques 4. Explain the 'try', 'catch', 'finally' and 'throw' keywords in Java.
'try' is used to enclose a block of code where exceptions might occur. 'catch' is used to handle exceptions. 'finally' is used to define a block of code that will be executed whether an exception is thrown or not. 'throw' is used to explicitly throw an exception.
Most helpful rated by users: