try{}finally{},,try{}这里执行完转向后finally{}还执行吗打个比方:
try{////打开数库进行一些操作
request.getrequestdispacther().fowrwad()//转向}
finally{/////关闭数据库方法}
教程上说finally中的代码是必执行代码。不知道转向后还会不会执行?
try{////打开数库进行一些操作
request.getrequestdispacther().fowrwad()//转向}
finally{/////关闭数据库方法}
教程上说finally中的代码是必执行代码。不知道转向后还会不会执行?
try {
request.getrequestdispacther().fowrwad();
System.out.println("Hello");
return;
} finally {
System.out.println("World");
}
try {
request.getrequestdispacther().fowrwad();
System.out.println("Hello");
System.exit(1);如果词语调用System.exit(1);则finally语句是不会执行的!因为你已经终止Java运行。
return;
}finally {
System.out.println("World");
}
try {
System.out.println("aaa");
System.out.println("Hello");
System.exit(0); //中断程序!
return;
} finally {
System.out.println("World");
}这样后面的finally里的就不执行了,如果面试的时候面试官问你你就这样回答!
顶死
public class Test {
public static void main(String[] args) {
try {
System.out.println("try");
System.exit(0);
} finally {
System.out.println("finally");
}
}
}当然这是个特例,但如果是Y/N的选择题,一定要选择N