是否可以在不使用 try catch 块的情况下将抛出的异常写入文件?
例如
public static void method() throws Exception, SQLException{
if(Exception is thrown){
write Exception to out.txt;
write SQLException to out.txt;
}
}
还是您必须这样做:
public static void method(){
try{
...
}catch(Exception ex){
write ex to file;
}catch(SQLException sqlex){
write sqlex to file;
}
}