异常类的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)

你可能感兴趣的:(异常类的printStackTrace()方法)