集册 Java实例教程 将异常堆栈跟踪保存到字符串

将异常堆栈跟踪保存到字符串

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

547
将异常堆栈跟踪保存到字符串

 //from nowjava - 时  代  Java

import java.io.PrintWriter;

import java.io.StringWriter;


public class Main {

  public static void main(String args[]) {


    try {

      // this will throw NumberFormatException

      Integer.parseInt("Not a number");


    } catch (NumberFormatException e) {



      StringWriter sWriter = new StringWriter();


      PrintWriter pWriter = new PrintWriter(sWriter);


      e.printStackTrace(pWriter);


      String strStackTrace = sWriter.toStri
展开阅读全文