怀疑异常处理,最后在java中阻止 [英] Doubt in exception handling and finally block in java
本文介绍了怀疑异常处理,最后在java中阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码:
你可以告诉我们如何做吗? code> 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() ;
//控件正在这个块本身停止,但我想打印下面的语句
}
//我需要打印此语句,无论发生什么异常
系统.out.println(结束程序);
}
}
解决方案
添加另一个最终块
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); ---->我需要打印此声明,无论发生什么异常
}
}
}
或者,如果你知道只有你处理的例外情况,你可以完全放下最后的块。
Can you tell the idea of how to doing it?
Code :
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");
}
}
解决方案
Just add another finally block
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
}
}
}
Or, if you know there are gonna be only the exceptions that you handle, you can just drop the finally blocks altogether.
这篇关于怀疑异常处理,最后在java中阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文