异常中的finally和方法中的return


含有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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值