Tutorial 08
Tutorial 08
Tutorial-08
Objective: The main objective of this tutorial is to learn about the exception handling of Java
language.
try{
School of Computer Science Engineering and Technology
System.out.println("Bennett");
int i = 10/0;
System.out.println("University");
}
catch(NullPointerException e)
{
System.out.println("Exception" + e.getMessage());
}
}
}
try{
System.out.println("Bennett");
String s = null;
System.out.println(s.length());
}
catch(Exception e)
{
System.out.println("Exception" + e.getMessage());
}
catch(NullPointerException e)
{
System.out.println("Exception" + e.getMessage());
}
}
}
System.out.println(s.length());
}
catch(NullPointerException e)
{
System.out.println("Exception: " + e.getMessage());
}
try{
int a[] = new int[5];
a[6] = 10;
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Exception: " + e.getMessage());
}
}
catch(Exception e)
{
}
}
}
class Main{
public static void main(String args[]){
try{
int data=25/0;
System.out.println(data);
}
finally{
System.out.println("finally block is always executed");
}
System.out.println("rest of the code...");
}
School of Computer Science Engineering and Technology
8.6 What is output of below code?
import java.io.IOException;
void p(){
try{
n();
}catch(Exception e)
{
System.out.println("exception handled");
System.out.println("normal flow...");
}
}