-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathExample9.java
More file actions
34 lines (28 loc) · 848 Bytes
/
Example9.java
File metadata and controls
34 lines (28 loc) · 848 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
27
28
29
30
31
32
33
34
package javatips.exception;
/**
* 包装异常不要丢弃原始异常
*
* @author biezhi
* @date 2018/9/18
*/
public class Example9 {
class MyBusinessException extends Exception {
public MyBusinessException(String message) {
super(message);
}
public MyBusinessException(String message, Throwable cause) {
super(message, cause);
}
}
public void wrapException(String id) throws MyBusinessException {
try {
long userId = Long.parseLong(id);
System.out.println("userId: " + userId);
} catch (NumberFormatException e) {
throw new MyBusinessException("描述错误的消息", e);
}
}
public static void main(String[] args) throws MyBusinessException {
new Example9().wrapException("emmm");
}
}