class ExceptionInfo {
public static void main(String[] args) {
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("F:\\exception.log");
ps.println(s);
e.printStackTrace(ps);
} catch (IOException ex) {
throw new RuntimeException("日志文件创建失败");//只要是有错误,程序就会提示,这是运行时错误,你虽然把错误打印在的文件中,但是没有处理掉,所以在控制太还会出错误!
}
e.printStackTrace(System.out);