forked from levelp/java_01
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyClass.java
More file actions
26 lines (25 loc) · 777 Bytes
/
MyClass.java
File metadata and controls
26 lines (25 loc) · 777 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
// Класс для демонстрации различных видов исключений
public class MyClass {
public static void main(String[] args)
throws MyException {
MyClass myClass = new MyClass();
try {
myClass.method1(1);
} catch (MyRuntimeException e) {
System.out.println("Поймал: "
+ e);
}
myClass.method1(2);
myClass.method1(3);
}
private void method1(int exceptionNumber) throws MyException {
switch (exceptionNumber) {
case 1:
throw new MyRuntimeException();
case 2:
throw new MyError();
case 3:
throw new MyException();
}
}
}