-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexceptions.java
77 lines (61 loc) · 2.2 KB
/
exceptions.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.io.*;
import java.util.*;
class test
{
private void hi(){}
}
class q3
{
public static void main(String[] args)
{
try
{
Scanner sc1 = new Scanner(System.in);
System.out.println("Enter the file name to be read :");
String w = sc1.next();
w += ".txt";
Scanner sc = new Scanner(new File(w));
System.out.println("The file has been read.");
sc.close();
System.out.println("---------------------------------------------------");
int a = 22/0;
sc1.close();
System.out.println("---------------------------------------------------");
int arr[] = {1, 3, 4, 5};
System.out.println(arr[44]);
System.out.println("---------------------------------------------------");
String s = "abc";
System.out.println(s.charAt(44));
System.out.println("---------------------------------------------------");
String ss=null;
System.out.println(ss);
System.out.println("---------------------------------------------------");
int arr1[] = new int[-100];
System.out.println("---------------------------------------------------");
}
catch(FileNotFoundException e1)
{
System.out.println("The specfied file cannot be found.");
}
catch(ArithmeticException e2)
{
System.out.println("Cannot divide by zero.");
}
catch(ArrayIndexOutOfBoundsException e3)
{
System.out.println("The index of the array is larger than the length of the array.");
}
catch(StringIndexOutOfBoundsException e4)
{
System.out.println("The index of the String is larger than the length of the String.");
}
catch(NullPointerException e5)
{
System.out.println("NULL pointers cannot be used.");
}
catch(NegativeArraySizeException e6)
{
System.out.println("Array size cannot be negtive.");
}
}
}