含有finally,不顾一切执行。
Java中的return语句总是和方法有密切关系,return语句总是用在方法中,有两个作用,一个是返回方法指定类型的值(这个值总是确定的),
一个是结束方法的执行(仅仅一个return语句)。
package org.gjs;
public class Demo {
protected static void fun(){
try{
System.out.println("1");
int i=Integer.parseInt("a");
}catch(Exception e){
System.out.println("2");
}
System.out.println("3");
}
public static void main(String []args){
fun();
}
}
结果1,2,3
package org.gjs;
public class Demo {
protected static void fun(){
try{
System.out.println("1");
int i=Integer.parseInt("a");
return;
}catch(Exception e){
System.out.println("2");
}
System.out.println("3");
}
public static void main(String []args){
fun();
}
}
结果1,2,3
package org.gjs;
public class Demo {
protected static void fun(){
try{
System.out.println("1");
return;
}catch(Exception e){
System.out.println("2");
}
System.out.println("3");
}
public static void main(String []args){
fun();
}
}
结果1
package org.gjs;
public class Demo {
protected static void fun(){
try{
System.out.println("1");
return;
}catch(Exception e){
System.out.println("2");
}
finally{System.out.println("3");}
}
public static void main(String []args){
fun();
}
}
结果:1,3
|