try catch finally return?
来源:互联网 发布:网络设备网管软件 编辑:程序博客网 时间:2024/05/22 15:00
/** * try catch finally 中含有return 总结 * Created by nier_ni on 2014/8/6. */public class TrySequency { /** * try catch finally 没有异常 没有return 正常执行 */ public static void tryNoException(){ try{ System.out.println("try块执行"); }catch(Exception e){ System.out.println("catch块执行"); }finally{ System.out.println("finally块执行"); } } /** * try 中异常 catch finally */ public static void tryException(){ int i = 0; try { System.out.println("try块执行"); int j = 5/i; }catch (Exception e){ System.out.println("catch块执行"); }finally { System.out.println("finally块执行"); } } /** * try 中有return catch finally 没有异常 */ public static String tryReturnNoException(){ try { System.out.println("tryReturnNoException中try"); return "try 中 return"; }catch (Exception e){ System.out.println("tryReturnNoException中catch"); }finally { System.out.println("tryReturnNoException中finally"); } return "0"; } /** * try 中有return catch finally 有异常 */ public static String tryReturnException(){ int i = 0; try { System.out.println("tryReturnException中try"); int j = 5 / i; return "try 中 return"; }catch (Exception e){ System.out.println("tryReturnException中catch"); }finally { System.out.println("tryReturnException中finally"); } return "0"; } /** * try catch finally 之后有return 没有异常 */ public static String tryNoExceptionFinallyReturn(){ try{ System.out.println("try块执行"); }catch(Exception e){ System.out.println("catch块执行"); }finally{ System.out.println("finally块执行"); } return "finally之后的return"; } /** * try catch finally 之后有return 有异常 */ public static String tryExceptionFinallyReturn(){ int i = 0 ; try{ System.out.println("try块执行"); int j = 3/0; }catch(Exception e){ System.out.println("catch块执行"); }finally{ System.out.println("finally块执行"); } return "finally之后的return"; } /** * try catch finally (catch finally中有return)返回那个return */ public static int tryExceptionCatchFinallyReturnNoException(){ int i = 1; try { System.out.println("try块开始执行\t" + i ); int j = 5/i; }catch(Exception e){ System.out.println("catch块开始执行\t" + i); i++; return i; }finally { System.out.println("finally块开始执行\t" + i); i = 100; } return i; } /** *try catch finally(catch finally 中有return)有异常 返回那个return */ public static int tryExceptionCatchFinallyException(){ int i = 0; try { System.out.println("try块开始执行\t" + i ); int j = 5/i; }catch(Exception e){ System.out.println("catch块开始执行\t" + i); i++; return i; }finally { System.out.println("finally块开始执行\t" + i); i = 100; } return i; } public static void main(String[] args) { /*System.out.println("try catch finally 没有异常 没有return 正常执行"); tryNoException(); System.out.println("----------try 中异常 catch finally------------"); tryException(); System.out.println("-----try 中有return catch finally 没有异常-----"); System.out.println(tryReturnNoException()); System.out.println("-----try 中有return catch finally 有异常-----"); System.out.println(tryReturnException()); System.out.println("-----try catch finally 之后有return 没有异常-----"); System.out.println(tryNoExceptionFinallyReturn()); */ /* System.out.println("-----try catch finally 之后有return 有异常-----"); System.out.println(tryExceptionFinallyReturn()); System.out.println("-------try catch finally (catch finally中有return)--------没有异常"); System.out.println(tryExceptionCatchFinallyReturnNoException());*/ System.out.println("------try catch finally(catch finally中有return)------有异常"); System.out.println(tryExceptionCatchFinallyException()); }}
0 0
- try catch finally return?
- try catch finally return
- try catch finally return
- try...catch...finally中的return
- try catch finally 和return
- try、catch、finally巧遇return
- try、catch、finally巧遇return
- try...catch...finally中的return
- try、catch、finally巧遇return
- try catch finally与return
- 研究try catch finally return
- try、catch、finally、return关系
- try, catch, finally, return的执行顺序
- try、catch、finally、return的执行顺序
- 在try-catch-finally中, return
- try、catch、finally、return的执行顺序
- try catch finally中的return 问题
- try catch finally return 的执行顺序
- 百度地图中的controller
- zookeeper 的Watcher机制实现
- java的JDK的安装配置图文详解
- js报错
- (深度搜索)The House Of Santa Claus
- try catch finally return?
- JavaScript继承详解(五)
- eclipse使用技巧学习
- abstract class和interface的剖析
- ZOJ - 1654 Place the Robots (构图 最大匹配)
- Jquery单选按钮的赋值
- 【note】EtherCAT Configurator 使用之主菜单介绍
- 多看几个浪费快乐放假啊说的是发动机
- hdu 1452 Happy 2004