day19/ExceptionInfo.java

来源:互联网 发布:中银淘宝卡办理 编辑:程序博客网 时间:2024/05/19 17:26
import java.io.*;import java.util.*;import java.text.*;class ExceptionInfo {public static void main(String[] args) //throws IOException{try{int[] arr = new int[2];System.out.println(arr[3]);}catch (Exception e){try{Date d = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm-ss");String s = sdf.format(d);PrintStream ps = new PrintStream("exception.log");ps.println(s);System.setOut(ps);}catch (IOException ex){throw new RuntimeException("日志文件创建失败");}e.printStackTrace(System.out);}}}

0 0
原创粉丝点击