将异常(getStackTrace)转化成String

    private static String getStackMsg(Exception e) {  
      
            StringBuffer sb = new StringBuffer();  
            StackTraceElement[] stackArray = e.getStackTrace();  
            for (int i = 0; i < stackArray.length; i++) {  
                StackTraceElement element = stackArray[i];  
                sb.append(element.toString() + "\n");  
            }  
            return sb.toString();  
        }  
      
        private static String getStackMsg(Throwable e) {  
      
            StringBuffer sb = new StringBuffer();  
            StackTraceElement[] stackArray = e.getStackTrace();  
            for (int i = 0; i < stackArray.length; i++) {  
                StackTraceElement element = stackArray[i];  
                sb.append(element.toString() + "\n");  
            }  
            return sb.toString();  
        }  

分享到:

你可能感兴趣的:(Java基础)