Java每一天4 Thinking P268
2016-07-03 16:10
585 查看
package com.pm; public class Rethrowing { public static void f() throws Exception { System.out.println("originating the exception in f()"); throw new Exception("thrown from f()"); } public static void g() throws Throwable { try { f(); } catch (Exception e) { System.out.println("Inside g(), e.printStackTrace()"); e.printStackTrace(); throw e; // 17 /*originating the exception in f() Inside g(), e.printStackTrace() Caught in main, e.printStackTrace() java.lang.Exception: thrown from f() at com.pm.Rethrowing.f(Rethrowing.java:6) at com.pm.Rethrowing.g(Rethrowing.java:11) at com.pm.Rethrowing.main(Rethrowing.java:35) java.lang.Exception: thrown from f() at com.pm.Rethrowing.f(Rethrowing.java:6) at com.pm.Rethrowing.g(Rethrowing.java:11) at com.pm.Rethrowing.main(Rethrowing.java:35)*/ //throw e.fillInStackTrace(); // 18 /* * originating the exception in f() Inside g(), e.printStackTrace() Caught in main, e.printStackTrace() java.lang.Exception: thrown from f() at com.pm.Rethrowing.f(Rethrowing.java:6) at com.pm.Rethrowing.g(Rethrowing.java:11) at com.pm.Rethrowing.main(Rethrowing.java:23) java.lang.Exception: thrown from f() at com.pm.Rethrowing.g(Rethrowing.java:17) at com.pm.Rethrowing.main(Rethrowing.java:23) */ } } public static void main(String[] args) throws Throwable { try { g(); } catch (Exception e) { System.out.println("Caught in main, e.printStackTrace()"); e.printStackTrace(); } } }
fillInStackTrace() 重新记录抛出信息
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树