读书人

使用StringWriter获取错误内容

发布时间: 2013-12-15 22:17:18 作者: rapoo

使用StringWriter获取异常内容

try{...} catch (Exception e) {e.printStackTrace();rspCode = String.valueOf(BaseException.RSP_SYS_ERROR_CODE);try {// TODO 发送邮件预警StringWriter sw = new StringWriter();          e.printStackTrace(new PrintWriter(sw, true));          String str = sw.toString();      String text = "账户: " + account + ", 代码: " + rspCode + "<br> 信息: " + str;    emailService.sendBatchMail(MailUtil.mailto, "warning", text, "登录失败预警");} catch (Exception e2) {e2.printStackTrace();}} finally { ...}


很实用~~

读书人网 >软件架构设计

热点推荐