// exceptions/Rethrowing.java// (c)2017 MindView LLC: see Copyright.txt// We make no guarantees that this code is fit for any purpose.// Visit http://OnJava8.com for more book information.// Demonstrating fillInStackTrace()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 Exception {try {f();} catch(Exception e) {System.out.println("Inside g(), e.printStackTrace()");e.printStackTrace(System.out);throw e;}}public static void h() throws Exception {try {f();} catch(Exception e) {System.out.println("Inside h(), e.printStackTrace()");e.printStackTrace(System.out);throw (Exception)e.fillInStackTrace();}}public static void main(String[] args) {try {g();} catch(Exception e) {System.out.println("main: printStackTrace()");e.printStackTrace(System.out);}try {h();} catch(Exception e) {System.out.println("main: printStackTrace()");e.printStackTrace(System.out);}}}/* Output:originating the exception in f()Inside g(), e.printStackTrace()java.lang.Exception: thrown from f()at Rethrowing.f(Rethrowing.java:8)at Rethrowing.g(Rethrowing.java:12)at Rethrowing.main(Rethrowing.java:32)main: printStackTrace()java.lang.Exception: thrown from f()at Rethrowing.f(Rethrowing.java:8)at Rethrowing.g(Rethrowing.java:12)at Rethrowing.main(Rethrowing.java:32)originating the exception in f()Inside h(), e.printStackTrace()java.lang.Exception: thrown from f()at Rethrowing.f(Rethrowing.java:8)at Rethrowing.h(Rethrowing.java:22)at Rethrowing.main(Rethrowing.java:38)main: printStackTrace()java.lang.Exception: thrown from f()at Rethrowing.h(Rethrowing.java:27)at Rethrowing.main(Rethrowing.java:38)*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。