Exception
Exception
CLASS-12
Exception Handling
1. Define exception.
An exception is an unwanted or unexpected event, which occurs during the execution of a
program i.e at run time, that disrupts the normal flow of the program’s instructions.
For example: an array index reference was out of range, or an attempt was made to divide an
integer by zero.
2. How exceptions can be handled in Java?
try - A try block surrounds the part of the code that can generate exception(s).
catch – The catch blocks follow a try block. A catch block contains the exception handler -
specific code that is executed when the exception occurs. Multiple catch blocks following a try
block can handle different types of exceptions.
try {
finally {
}
3. Give an example of exception handling.