java 异常(二)代码
来源:互联网 发布:已恢复的网络购彩 编辑:程序博客网 时间:2024/06/03 21:44
package com.apricotforest.cloudfollowup.patient.controller;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;public class TestException { public TestException() { } boolean testEx() throws Exception { boolean ret = true; try { ret = testEx1(); if (!ret) { return false; } } catch (Exception e) { System.out.println("testEx, catch exception"); ret = false; throw e; } finally { System.out.println("testEx, finally; return value=" + ret); return ret; } } boolean testEx1() throws Exception { boolean ret = true; try { ret = testEx2(); if (!ret) { return false; } System.out.println("testEx1, at the end of try"); return ret; } catch (Exception e) { System.out.println("testEx1, catch exception"); ret = false; throw e; } finally { System.out.println("testEx1, finally; return value=" + ret); return ret; } } boolean testEx2() throws Exception { boolean ret = true; try { int b = 12; int c; for (int i = 2; i >= -2; i--) { c = b / i; System.out.println("i=" + i); } return true; } catch (Exception e) { System.out.println("testEx2, catch exception"); ret = false; throw e; } finally { System.out.println("testEx2, finally; return value=" + ret); return ret; } } public String openFile() { try { FileInputStream inputStream = new FileInputStream("/Users/baowenwei/Downloads/sql.txt"); int ch = inputStream.read(); inputStream.close(); System.out.println("aaa"); return "step1"; } catch (FileNotFoundException e) { System.out.println("file not found"); return "step2"; }catch (IOException e) { System.out.println("io exception"); return "step3"; }finally{ System.out.println("finally block"); return "finally"; } } public static void main(String[] args) { TestException testException1 = new TestException(); try { testException1.testEx(); System.out.println(testException1.openFile()); } catch (Exception e) { e.printStackTrace(); } }}
查看原文:http://www.baowenwei.com/archives/836
0 0
- java 异常(二)代码
- Java异常(二)
- java异常处理(二)
- JAVA异常学习(二)
- java异常分析(二)
- Java异常处理(二)
- Java异常Exception(二)
- Java异常处理(二)
- JAVA代码(二)
- Java开发代码规范之异常日志(二)——日志规约
- Java当中的异常(二)
- java异常学习二(总结)
- JAVA第十四弹(异常处理二)
- java中的异常处理(二)
- Java异常的处理机制(二)
- Java异常学习笔记(二)
- 黑马程序员--java基础--异常(二)
- Java4Android-Java当中的异常(二)
- 使用FormData对象
- Postgres的Standby数据库搭建,异步流复制示例及同步流复制实例
- std::set
- 电阻屏和电容屏的区别
- git 本地代码仓库搭建
- java 异常(二)代码
- ubuntu五笔输入法设置过程
- Material Design
- 数字签名和加密的区别
- 三大框架整合
- 说说JSON和JSONP,也许你会豁然开朗
- Java GUI做简易计算器
- LeetCode Isomorphic Strings
- IOS xcode 删除git使用svn