Repository navigation
Expand file tree
/
Copy pathSolution.java
More file actions
52 lines (43 loc) · 1.41 KB
/
Copy pathSolution.java
File metadata and controls
52 lines (43 loc) · 1.41 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
package com.javarush.task.task09.task0915;
import java.io.CharConversionException;
import java.io.IOException;
import java.nio.file.FileSystemException;
/*
Перехват выборочных исключений
*/
public class Solution {
public static StatelessBean BEAN = new StatelessBean();
public static void main(String[] args) {
try {
processExceptions();
} catch (FileSystemException e) {
BEAN.log(e);
}
}
public static void processExceptions() throws FileSystemException {
try {
BEAN.methodThrowExceptions();
} catch (FileSystemException e) {
BEAN.log(e);
throw e;
} catch (CharConversionException e) {
BEAN.log(e);
} catch (IOException e) {
BEAN.log(e);
}
}
public static class StatelessBean {
public void log(Exception exception) {
System.out.println(exception.getMessage() + ", " + exception.getClass().getSimpleName());
}
public void methodThrowExceptions() throws CharConversionException, FileSystemException, IOException {
int i = (int) (Math.random() * 3);
if (i == 0)
throw new CharConversionException();
if (i == 1)
throw new FileSystemException("");
if (i == 2)
throw new IOException();
}
}
}