异常类的printStackTrace()方法

 

显示“抵达异常掷出点之前的一连串函数调用过程”到指定的输出目的地。

  1. public class TestException {
  2.     public static void main(String[] args) {
  3.         TestException te = new TestException();
  4.         te.f1();
  5.         System.out.println("main");
  6.     }
  7.     
  8.     void f1(){
  9.         f2();
  10.         System.out.println("f1");
  11.     }
  12.     
  13.     void f2(){
  14.         try{
  15.             f3();
  16.         }catch(Exception e){
  17.             e.printStackTrace();
  18.         }       
  19.         System.out.println("f2");
  20.     }
  21.     void f3()throws Exception{
  22.         f4();
  23.         System.out.println("f3");
  24.     }
  25.     void f4()throws Exception{
  26.         f6();
  27.         f5();
  28.         System.out.println("f4");
  29.     }
  30.     
  31.     void f5() throws Exception{
  32.         throw new Exception(); 
  33.     }
  34.     
  35.     void f6(){
  36.     }
  37. }
  38. output:
  39. f2
  40. f1
  41. main
  42. java.lang.Exception
  43.     at TestException.f5(TestException.java:35)
  44.     at TestException.f4(TestException.java:30)
  45.     at TestException.f3(TestException.java:24)
  46.     at TestException.f2(TestException.java:16)
  47.     at TestException.f1(TestException.java:10)
  48.     at TestException.main(TestException.java:5)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值