-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptionHandling.java
43 lines (42 loc) · 1.3 KB
/
exceptionHandling.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
public class exceptionHandling {
public static void main(String[] args) {
try{
int a=5/0;
}
catch(ArithmeticException e)
{
System.out.println("Arithmetic Exception occured\n"+"Message:"+ e.getMessage()+"\n");
}
try{
String s=null;
System.out.println(s.hashCode());
}
catch(NullPointerException e)
{
System.out.println("Null Pointer Exception occured\n"+"Message:"+ e.getMessage()+"\n");
}
try{
String s="hi";
int a=Integer.parseInt(s);
}
catch(NumberFormatException e)
{
System.out.println("Number Format Exception occured\n"+"Message:"+ e.getMessage()+"\n");
}
try{
int a[]=new int[10];
System.out.println(a[40]);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("ArrayIndexOutOfBounds Exception occured\n"+"Message:"+ e.getMessage()+"\n");
}
try{
FileInputStream w=new FileInputStream("abc.txt");
}
catch(IOException e)
{
System.out.println("IO Exception occured\n"+"Message:"+ e.getMessage()+"\n");
}
}
}