我想尝试使用资源块(PrintWrtiter或FileWriter)在关闭资源时引发异常,以便我可以打印它。
public PrintWriter func throws CustomException{
String filename = "file.txt";
try(PrintWriter feedError = new PrintWriter(new FileWriter(filename ,
true))){
feedError.println("writing in a file");
return feedError;
} catch (Exception e){
e.printStackTrace();
Throwable[] supp = e.getSuppressed();
System.Out.Println(supp);
throw new CustomException("file not found");
}
}
预期java.lang.Exception
:关闭PrintWriter或FileWriter时出错