-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptions_02.java
More file actions
33 lines (28 loc) · 861 Bytes
/
Copy pathExceptions_02.java
File metadata and controls
33 lines (28 loc) · 861 Bytes
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
public class Exceptions_02{
public static void main(String[] args){
int i=18;
int j=0;
int arr[]=new int[5];
String s=null;
try
{
j=2;
System.out.println(i/j); //trying to divide by zero
System.out.println(arr[2]); //trying to access the element out of the limit of array
System.out.println(s.length());
}
catch(ArithmeticException e)
{
System.out.println("Can not divide by zero.");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("trying to access beynd the array limit");
}
catch(Exception e)
{
System.out.println("Something went wrong..."+e);
}
System.out.println("Outside the try catch block...");
}
}