获取异常具体信息 尤其是运行时异常例如NullPointerException 比e.getMessage()更详细

///打印异常信息  尤其是运行时异常  比getMessage()更详细
public static String getMessageInfo(Exception e){
OutputStream ops =new ByteArrayOutputStream();
PrintStream ps=new PrintStream(ops);
e.printStackTrace(ps);
ps.close();
try {
ops.close();
} catch (IOException e1) {
e1.printStackTrace();
}finally {
return ops.toString();
}
}

猜你喜欢

转载自www.cnblogs.com/happydaytome/p/13403910.html