You are on page 1of 13

Exception

Handling
To

MS. AYESHA KHATUN


Lecturer
Dept. of CSE JOY PAL
Green University ID: 201002418
Sec.: 203DA
Dept. of CSE
Green University

By
Index

Keywords
Exception
Exception & Example
Handling
Uses
Exception

 An exception is a run time error

• ArithmeticException
• NullPointerException
• ArrayIndexOutOfBoundsException etc.
Exception Handling

Mechanism to handle the runtime errors so


that the normal flow of the application can be
maintained.
Keywords

 Try
 Catch
 Finally
 Throw
 Throws
Try
try{
try{
//Statements to execute
}catch(ArithmeticException e){
System.out.println(e);
}
try{
int a[] = new int [5]; a[5] = 4;
}
}
Catch
try{
//Protected Code
}
catch(Exception e1){
//catch block
}
catch(Exception e2){
// Catch Block
}
catch(Exception e3){
//Catch Block
}
Finally
Used to execute the important code of the program.

try{
//Protected Code
}
catch(Exception e1){
//catch block
}
catch(Exception e2){
// Catch Block
}
finally{
//The block is always executed
}
Throw

Used to throw an exception.

Syntax:

Void a ( ) {
throw new ArithmeticException (“ Incorrect ”);
}
Throws

Used to declare exceptions.

Syntax:

Void a( ) throws ArithmeticException {

}
Example

class Exception{
public static void main (String args [ ]){
try{
//code that may raise exception
}
catch(Exception e){
// rest of the program
}
}
}

You might also like