public static String getStackTrace(Throwable throwable)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try
{
throwable.printStackTrace(pw);
return sw.toString();
} finally
{
pw.close();
}
}
测试
public static void test()
{
try
{
int i = 0;
int m = 10 / i;
} catch (Exception e)
{
System.out.println(e.getMessage());
System.out.println("------调皮的分割线------");
System.out.println(ExceptionUtil.getStackTrace(e));
}
}
1078

被折叠的 条评论
为什么被折叠?



