Ganpat University: Akshi Vasaniya
Ganpat University: Akshi Vasaniya
Ganpat University
(Practical-8)
try {
func(5, 0);
} catch(ArithmeticException e){
System.out.println("Exception: "+e.getMessage());
}
}
}
Output-
try {
func(null);
} catch(ArrayIndexOutOfBoundsException e){
System.out.println("Exception: "+e.getMessage());
} catch(NumberFormatException e) {
System.out.println("Exception :
"+e.getMessage());
} catch(NullPointerException e) {
System.out.println("Exception: "+e.getMessage());
}
finally {
System.out.println("Sorry for inconvenience");
}
int z = Integer.parseInt("null");
System.out.println(s.length());
}
}
Output –
try {
throw new MyException("Exception fierd");
} catch(MyException e) {
System.out.println("Its my exception");
System.out.println(e.getMessage());
}
public MyException(String s) {
super(s);
}
Output –
Thread.sleep(5000);
System.out.println("Hello World");
Output –