看多了,思考就多了.
Topic source自己挖的坑自己填
public class Test04 {
public static void main(String[] args) throws Exception {
Exception origin = null;
try {
System.out.println(Integer.parseInt("abc"));
} catch (NumberFormatException e) {
origin = e;
throw e;
} catch (Exception e) {
origin = e;
throw e;
} finally {
Exception e = new IllegalArgumentException();
if (origin != null) {
e.addSuppressed(origin);
}
throw e;
}
}
}
不知道还可不可以优化...100个catch 要写100次么?
- 1
🌙
多个catch 语句
是否是设置多个变量依次判断添加呢?
这样就感觉有点蠢啦~~~
有兴趣的同学可以试试,我要回家啦~~~~