持续完善中…
try catch中e.printStackTrace()的作用?
此处调用测试方法:
@Test
public void create01() {
String filePath = "e:\\JavaI\\news1.txt";
File file = new File(filePath);
try {
file.createNewFile();
System.out.println("文件创建成功!");
} catch (IOException e) {
System.out.println("e1:"+e);
e.printStackTrace();
System.out.println("e2:"+e);
}
}
filePath
指定的是一个不存在的路径,报错信息如下:
删除e.printStackTrace();
再进行测试,报错信息如下:
可知e.printStackTrace();
的作用是在命令行打印异常信息在程序中出错的类型以及位置。