Posts

Showing posts with the label finally

Quick Refresh : Java : Exception Handling

Image
Java : Exception Handling Q1) What is an Exception? Ans) The exception is said to be thrown whenever an exceptional event occurs in java which signals that something is not correct with the code written and may give unexpected result. An exceptional event is a occurrence of condition which alters the normal program flow. Exception handler is the code that does something about the exception. Q2) Exceptions are defined in which java package? Ans)All the exceptions are subclasses of java.lang.Exception Q3) How are the exceptions handled in java? Ans)When an exception occurs the execution of the program is transferred to an appropriate exception handler.The try-catch-finally block is used to handle the exception. The code in which the exception may occur is enclosed in a try block, also called as a guarded region. The catch clause matches a specific exception to a block of code which handles that exception. And the clean up code which needs to be executed no matter the exception occur...