创建文档bug.txt,来收集异常
即每次抛出异常时,将异常写入文档中
代码示例:
try {
String s = null;
s.toString();
}catch(Exception e){
PrintWriter pw = new PrintWriter("d:" + File.separator + "bug.txt");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
pw.println(sdf.format(new Date()));
e.printStackTrace(pw);
pw.close();
}
执行结果:
d盘创建"bug.txt"文档并写入内容:
2021-07-09 12:12
java.lang.NullPointerException
at com.company.online.t0103.t03_IO.ExceptionTxt.main(ExceptionTxt.java:14)