raj*_*aja 2 java exception-handling
你能说出怎么做的想法吗?
代码:
public void main(String[] args) {
try {
//Some Exception throws here
}
catch(SomeException se) {
se.printStackTrace();
}
finally {
try {
//SomeException1 throws here
}
catch(SomeException1 se1) {
se.printStackTrace();
//Control is getting stop in this block itself but i wanna print the below statement
}
// I need to print this statement whatever exception occurs
System.out.println("End Program");
}
}
Run Code Online (Sandbox Code Playgroud)
只需添加另一个finally块
public void main(String[] args) {
try {
//Some Exception throws here
}
catch(SomeException se) {
se.printStackTrace();
}
finally {
try {
//SomeException1 throws here
}
catch(SomeException1 se1) {
se.printStackTrace();
}
finally {
System.out.println("End Program"); ----> I need to print this statement whatever exception occurs
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者,如果你知道只有你处理的异常,你可以完全删除finally块.