try--catch--finally中return返回值执行的顺序
public static int NoException(){
int i=10;
try{
System.out.println("i in try block is:"+i);
return --i;
}
catch(Exception e){
--i;
System.out.println("i in catch - form try block is:"+i);
return --i;
}
finally{
System.out.println("i in finally - from try or catch block is:"+i);
return --i;
}
}
public static void main(String[] args) {
System.out.println("=============NoException==================");
System.out.println(NoException());
System.out.println("===============================");
}
=============NoException==================
i in try block is:10
i in finally - from try or catch block is:9
8
===============================
public static int NoException1(){
int i=10;
try{
System.out.println("i in try block is:"+i);
return --i;
}
catch(Exception e){
--i;
System.out.println("i in catch - form try block is:"+i);
return --i;
}
finally{
System.out.println("i in finally - from try or catch block is:"+i);
--i;
System.out.println("i in finally block is:"+i);
//return --i;
}
}
=============NoException1==================
i in try block is:10
i in finally - from try or catch block is:9
i in finally block is:8
9
===============================
public static int WithException(){
int i=10;
try{
System.out.println("i in try block is:"+i);
i = i/0;
return --i;
}
catch(Exception e){
System.out.println("i in catch - form try block is:"+i);
--i;
System.out.println("i in catch block is:"+i);
return --i;
}
finally{
System.out.println("i in finally - from try or catch block is--"+i);
--i;
System.out.println("i in finally block is--"+i);
return --i;
}
}
=============WithException==================
i in try block is:10
i in catch - form try block is:10
i in catch block is:9
i in finally - from try or catch block is--8
i in finally block is--7
6
===============================
public static int WithException1(){
int i=10;
try{
System.out.println("i in try block is:"+i);
i=i/0;
return --i;
}catch(Exception e){
System.out.println("i in catch - form try block is:"+i);
return --i;
}finally{ System.out.println("i in finally - from try or catch block is:"+i);
--i;
System.out.println("i in finally block is:"+i);
//return i;
}
}
=============WithException1==================
i in try block is:10
i in catch - form try block is:10
i in finally - from try or catch block is:9
i in finally block is:8
9
===============================
public static int WithException2(){
int i=10;
try{
System.out.println("i in try block is:"+i);
i=i/0;
return --i;
}
catch(Exception e){
System.out.println("i in catch - form try block is:"+i);
int j = i/0;
return --i;
}
finally{ System.out.println("i in finally - from try or catch block is:"+i);
--i;
--i;
System.out.println("i in finally block is:"+i);
return --i;
}
=============WithException2==================
i in try block is:10
i in catch - form try block is:10
i in finally - from try or catch block is:10
i in finally block is:8
7
===============================
public static int WithException3(){
int i=10;
try{
System.out.println("i in try block is:"+i);
i=i/0;
//return --i;
}
catch(Exception e){
System.out.println("i in catch - form try block is:"+i);
//int j = i/0;
//return --i;
}
finally{ System.out.println("i in finally - from try or catch block is:"+i);
--i;
--i;
System.out.println("i in finally block is:"+i);
//return --i;
}
return --i;
}
=============WithException3==================
i in try block is:10
i in catch - form try block is:10
i in finally - from try or catch block is:10
i in finally block is:8
7
===============================
try--catch--finally中return返回值执行的顺序的更多相关文章
- try--catch--finally中return返回值执行的顺序(区别)
1.try块中没有抛出异常,try.catch和finally块中都有return语句 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public static int ...
- 用jquery的ajax方法获取return返回值的正确姿势
如果jquery中,想要获取ajax的return返回值,必须注意两方面,ajax的同步异步问题,在ajax方法里面还是外面进行return返回值. 下面列举了三种写法,如果想成功获取到返回值,参考第 ...
- 用jquery的ajax方法获取不到return返回值
如果jquery中,获取不到ajax返回值. 两个错误写法会导致这种情况:1.ajax未用同步 2.在ajax方法中直接return返回值. 下面列举了三种写法,如果想成功获取到返回值,参考第三种写法 ...
- 关于ExecuteNonQuery执行存储过程的返回值 、、实例讲解存储过程的返回值与传出参数、、、C#获取存储过程的 Return返回值和Output输出参数值
关于ExecuteNonQuery执行存储过程的返回值 用到过ExecuteNonQuery()函数的朋友们在开发的时候肯定这么用过. if(cmd.ExecuteNonQuery("xxx ...
- c++中带返回值函数没写return能通过编译但运行时会出现奇怪问题
c++中带返回值函数没写return能通过编译但运行时会出现奇怪问题 例如: string myFunc(){ theLogics(); } 发现调用: myFunc(); 崩溃. 但调用: cout ...
- C# 调用存储过程操作 OUTPUT参数和Return返回值
本文转载:http://www.cnblogs.com/libingql/archive/2010/05/02/1726104.html 存储过程是存放在数据库服务器上的预先编译好的sql语句.使用存 ...
- [改善Java代码]不要在finally块中处理返回值
在finally代码块中处理返回值,这是在面试题中经常出现的题目.但是在项目中绝对不能再finally代码块中出现return语句,这是因为这种处理方式非常容易产生"误解",会严重 ...
- 字节码分析finally块对return返回值的影响
直接进入主题.看如下代码: public int test(){ int i=0; try { i=1; return i; } catch (Exception e) { i=2; return i ...
- Asp.net MVC 中Controller返回值类型ActionResult
[Asp.net MVC中Controller返回值类型] 在mvc中所有的controller类都必须使用"Controller"后缀来命名并且对Action也有一定的要求: 必 ...
随机推荐
- python 类函数,实例函数,静态函数
一.实现方法 class Function(object): # 在类定义中定义变量 cls_variable = "class varibale" def __init__(se ...
- 用Web Services来整合.NET和J2EE
互用性(Interoperability)问题说起来容易但通常实现起来却比较困难.尽管Web service曾承诺要提供最佳的解决方案来衔接基于.NET和J2EE的应用程序,但其过程却并不简单.我们发 ...
- 【转】PHP 杂谈 坑爹的file_exists
转自:http://www.cnblogs.com/baochuan/archive/2012/05/06/2445822.html 介绍 我发现了一个问题,今天与大家分享.我把整个过程描述一下. ...
- asp.net学习——Response对象
(2011-03-29 07:33:03) 转载▼ 标签: 杂谈 分类: asp.net学习 响应的缓冲输出:为了提高服务器的性能,asp.net向浏览器Write的时候默认并不会每Write一次都会 ...
- C# 异步编程1 APM 异步程序开发
C#已有10多年历史,单从微软2年一版的更新进度来看活力异常旺盛,C#中的异步编程也经历了多个版本的演化,从今天起着手写一个系列博文,记录一下C#中的异步编程的发展历程.广告一下:喜欢我文章的朋友,请 ...
- C++基础学习一(基础之基础)
开篇:做了这么多年的软件,第一次使用博客的方式记录学习过程,之前都是笔记本(都有一摞了),因为之前一直从事的都是.NET的开发工作,对C++知之甚少,但一直想了解C++这门鼻祖级的语言,现在终于下定决 ...
- c# 百度地图api APP SN校验失败
在使用c#调用百度地图Web服务api遇到的签名(sn校验)问题,在此记录一下,(ip白名单校验的请忽略) 1.首先获取ak与sk,这个两个东西可以从控制台中获取到 2.在这个地址:sn签名算法,里面 ...
- 【PAT】B1075 链表元素分类(25 分)
这道题算有点难,心目中理想的难度. 不能前怕狼后怕虎,一会担心超时,一会又担心内存过大,直接撸 将三部分分别保存到vector 有意思的在于输出 分别输出第一个的add和num 中间输出nextadd ...
- ccf--20150303--节日
本题思路:首先,计算a月1日是星期几,然后再通过b和c得出日期monday,最后判断monday是否合法. 题目与代码如下: 问题描述 试题编号: 201503-3 试题名称: 节日 时间限制: 1. ...
- ARC设置
XCode兼容ARC和非ARC代码的方法 在ARC开发模式下引用非ARC文件或库需进行如下操作以告诉编译器此代码需按照非ARC模式对待: XCode中项目文件->TARGETS->Comp ...