How can I convert a stack trace to a string?

前端 未结 30 1161
再見小時候
再見小時候 2020-11-22 14:51

What is the easiest way to convert the result of Throwable.getStackTrace() to a string that depicts the stacktrace?

30条回答
  •  隐瞒了意图╮
    2020-11-22 15:27

    The solution is to convert the stackTrace of array to string data type. See the following example:

    import java.util.Arrays;
    
    try{
    
    }catch(Exception ex){
        String stack = Arrays.toString(ex.getStackTrace());
        System.out.println("stack "+ stack);
    }
    

提交回复
热议问题