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);
//重新定位向ps对象中输出?怎么理解?有和没有没什么区别啊?
System.setOut(ps);
}
catch(Exception ex)
{
throw new RuntimeException("日志文件创建失败");
}
//e.printStackTrace(System.out);
e.printStackTrace();
}
|
|