Java实现获取详细的异常信息

ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream pout = new PrintStream(out);
error.printStackTrace(pout);
String ret = new String(out.toByteArray());
pout.close();
try {
    out.close();
} catch (Exception e) {
    e.printStackTrace();
}
if (ret.length() > 300) {
    ret = ret.substring(0, 300);
}
LOG.info("异常信息 -> ");
LOG.info(ret);

 

你可能感兴趣的:(Java)