static void try_catch_finally_demo() {
{//Java 异常之:三步走
int opt = 1;
if (opt == 1) {
try {
} finally {
//wrong! should catch exception!
}
} else if (opt == 2) {
try {
} catch (Exception e) {
e.printStackTrace();
} finally {
//wrong! should catch Throwable!
//eg. *Error
}
} else if (opt == 3) {
try {
} catch (Throwable e) {
e.printStackTrace();
} finally {
//good, every Error.class will be catch!
}
}
//编程工具之函数查找:http://mathy.xyz/findFun.htm
}
}
willy2 发布了23 篇原创文章 · 获赞 5 · 访问量 3万+ 私信 关注