-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
127 lines (97 loc) · 4.17 KB
/
Solution.java
File metadata and controls
127 lines (97 loc) · 4.17 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//But the Counselor, the Holy Spirit, whom the Father will send in my name,
//he will teach you all things, and will remind you of all that I said to you. (John 14:26)
package com.javarush.task.task14.task1419;
import java.util.ArrayList;
import java.util.List;
import java.io.FileInputStream;
import java.io.File;
/*
Нашествие исключений
*/
public class Solution {
public static List<Exception> exceptions = new ArrayList<Exception>();
public static void main(String[] args) {
initExceptions();
for (Exception exception : exceptions) {
System.out.println(exception);
}
}
private static void initExceptions() { //it's first exception
try { //java.lang.ArithmeticException: / by zero
float i = 1 / 0;
} catch (Exception e) {
exceptions.add(e);
}
try{ //напишите тут ваш код
int[] array = new int[7];
System.out.println(array[7]); //java.lang.ArrayIndexOutOfBoundsException: 7
} catch (Exception f) {
exceptions.add(f);
}
try{
String string = "string";
Integer.parseInt(string); //java.lang.NumberFormatException: For input string: "string"
} catch (Exception g) {
exceptions.add(g);
}
try{
ArrayList list = new ArrayList();
list.get(7); //java.lang.IndexOutOfBoundsException: Index: 7, Size: 0
} catch (Exception h) {
exceptions.add(h);
}
try{
Object object = new Character('#');
System.out.println((Byte)object); //java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Byte
} catch (Exception i) {
exceptions.add(i);
}
try{
char[] array = new char[-7]; //java.lang.NegativeArraySizeException
} catch (Exception j) {
exceptions.add(j);
}
try{
String string = "string";
char c = string.charAt(7); //java.lang.StringIndexOutOfBoundsException: String index out of range: 7
} catch (Exception k) {
exceptions.add(k);
}
try{
String fileName = ""; //java.io.FileNotFoundException: (No such file or directory)
FileInputStream fis = new FileInputStream(fileName);
} catch (Exception l) {
exceptions.add(l);
}
try{
Class<?> cls = Class.forName(""); //java.lang.ClassNotFoundException:
} catch (Exception m) {
exceptions.add(m);
}
try{
File.createTempFile("prefix", "");//java.lang.SecurityException: Unable to create temporary file
} catch (Exception n) {
exceptions.add(n);
}
}
}
/*
java.lang.ArithmeticException: / by zero
java.lang.ArrayIndexOutOfBoundsException: 7
java.lang.NumberFormatException: For input string: "string"
java.lang.IndexOutOfBoundsException: Index: 7, Size: 0
java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Byte
java.lang.NegativeArraySizeException
java.lang.StringIndexOutOfBoundsException: String index out of range: 7
java.io.FileNotFoundException: (No such file or directory)
java.lang.ClassNotFoundException:
java.lang.SecurityException: Unable to create temporary file
Нашествие исключений
Заполни список exceptions десятью(10) различными исключениями.
Первое исключение уже реализовано в методе initExceptions.
Требования:
1. Список exceptions должен содержать 10 элементов.
2. Все элементы списка exceptions должны быть исключениями(потомками класса Throwable).
3. Все элементы списка exceptions должны быть уникальны.
4. Метод initExceptions должен быть статическим.
*/