集册 Java实例教程 打印异常的堆栈跟踪

打印异常的堆栈跟踪

欢马劈雪     最近更新时间:2020-01-02 10:19:05

543
打印异常的堆栈跟踪

public class Main { 

  public static void main(String[] args) {

    try {

      m1();/** 来 自 N o  w  J a v a . c o m - 时  代  Java**/

    }

    catch(MyException e) {      

      e.printStackTrace(); // Print the stack trace

    }

  }

  

  public static void m1() throws MyException {   

    m2();   

  }
  /** 
  来 自 
  时 代 J     a    v  a - nowjava.com
  **/


  public static void m2() throws MyException {

    throw new MyException("Some error has occurred.");

  }

}

class MyException extends Exception {

  public MyException() {

    super();

  }


  public MyException(String message) {

    super(message);

  }


  public MyExc
展开阅读全文