关于try-catch语句

<meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE">

<meta content="OpenOffice.org 3.2 (Linux)" name="GENERATOR"> <style type="text/css"> <!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } --> </style> public int testFinally(){

int x=10;

try{

x=20;

return x;

}catch(Exception e){

x=100;

}finally{

x=200;

System.out.println("int finally="+x);

}

return x;

}

在该方法中返回的x值是20,因为finally语句必须执行,所以执行x=20;这条语句后,遇到 <meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE">

<meta content="OpenOffice.org 3.2 (Linux)" name="GENERATOR"> <style type="text/css"> <!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } --> </style> return 语句, 将会暂停return 语句,但是return 语句内的值是20 将return中的值保存在内存中, 转而执行finally 语句, finally 语句执行完毕后,会执行刚return 语句,即返回20,但若是finally语句快中也有return语句的时候则只会执行finally语句中的renturn,而不会执行try或catch语句块中的return语句。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值