-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.java
More file actions
54 lines (48 loc) · 1.73 KB
/
example.java
File metadata and controls
54 lines (48 loc) · 1.73 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
package example.ExceptionExample;
/**
* Error exception.
*
* TODO: Next issues: What kinds of exception for java or list them?
*
* Reference:
* - https://www.liaoxuefeng.com/wiki/1252599548343744/1264734349295520
* - https://www.youtube.com/watch?v=1XAfapkBQjk
*/
public class example {
public static void main(String[] args) {
int number = 10;
int zero = 0;
try {
// example ex = new example();
// System.out.println("the result: " + ex.process());
// the same.
System.out.println("the result: " + division(number, zero));
} catch (BaseException e) {
System.out.println("base exceptiion: " + e);
} catch (ArithmeticException e) {
System.out.println("defined error. error message: " + e);
} catch (Exception e) {
System.out.println("general error. " + e);
} finally {
System.out.println("ending the process.");
}
try {
division2(10, 0);
} catch(NrBaseException e) {
System.out.println("NrBaseException Error Information: " + e + "; Error Message: " + e.message);
} catch(Exception e) {
System.out.println(e);
}
}
public int process() {
int molecular = 10; int Denominator = 0;
return division(molecular, Denominator);
}
public static int division(int molecular, int Denominator) {
return molecular / Denominator;
}
public static int division2(int molecular, int Denominator) {
// we defined a new custom exception to show it.
throw new NrDataException("data exception");
}
}