在Java開發中,我們經常要處理各種異常,我們一般用e.toString()或e.getMessage()得到異常信息,但是有時候異常堆棧中會存在很多信息,比如用下面的代碼拋出異常:
代碼如下:
public static String getErrmessage(Throwable t){
StringWriter stringWriter=new StringWriter();
t.printStackTrace(new PrintWriter(stringWriter,true));
return stringWriter.getBuffer().toString();
}
不做解釋。都能看懂