-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathJ2Lesson2.java
More file actions
43 lines (41 loc) · 1.11 KB
/
J2Lesson2.java
File metadata and controls
43 lines (41 loc) · 1.11 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
/**
* Java. Level 2. Lesson 2. Exception
* Examples for lesson
*
* @author Sergey Iryupin
* @version dated Jun 10, 2017
*/
class J2Lesson2 {
public static void main(String[] args) {
try {
justMethod();
} catch (NullPointerException ex) {
System.out.println(ex);
}
System.out.println("Main done!");
}
static void justMethod() throws NullPointerException {
System.out.println("We will try...");
int a = 0;
int[] arr = new int[5];
try {
//arr[5] = 12;
//int b = 10 / a;
throw new NullPointerException("NPE MY exception");
} catch (ArithmeticException ex) {
System.out.println(ex);
//System.exit(0);
//return;
} catch (ArrayIndexOutOfBoundsException ex) {
System.out.println(ex);
//System.exit(0);
//return;
//} catch (Exception ex) {
// System.out.println(ex);
}
finally {
System.out.println("Finally");
}
System.out.println("Done!");
}
}