为什么Java中的一些例外没有被捕获catch (Exception ex)?这是代码完全失败,出现未处理的异常.(Java版本1.4).
public static void main(String[] args) {
try {
//Code ...
} catch (Exception ex) {
System.err.println("Caught Exception");
ex.printStackTrace();
exitCode = app.FAILURE_EXIT_CODE;
}
finally {
app.shutdown();
}
System.exit(exitCode);
}
Run Code Online (Sandbox Code Playgroud)
我得到了 Exception in thread "main" java.lang.NoSuchMethodError
但这很有效
public static void main(String[] args) {
int exitCode = app.SUCCESS_EXIT_CODE;
try {
//Code ...
} catch (java.lang.NoSuchMethodError mex){
System.err.println("Caught NoSuchMethodError");
mex.printStackTrace();
exitCode = app.FAILURE_EXIT_CODE;
} catch (Exception ex) {
System.err.println("Caught Exception");
ex.printStackTrace();
exitCode = app.FAILURE_EXIT_CODE;
}
finally {
app.shutdown();
} …Run Code Online (Sandbox Code Playgroud)