GROOVY 异常处理 try catch
try catch finally
class Demo{
static void main(String[] args){
try{
File file = new File("./Example.txt");
FileReader fr = new FileReader(file);
}catch(Exception ex){
println ex;
}finally{
println "无论程序是否出错,此处的内容都会执行"
}
}
}
多异常捕获:
class Demo{
static void main(String[] args){
try{
def arr = new int[3];
arr[5] = 5;
}catch(ArrayIndexOutOfBoundsException ex){
println "Catching the Array out of Bounds exception"
}catch(Exception ex){
println "Catching the exception";
}finally{
println "无论程序是否出错,此处的内容都会执行"
}
}
}
浙公网安备 33010602011771号