在我的方法中,在下面的伪代码中,在一行中创建了两个异常(ArrayIndexOutOfBounds 和 NumberFormatException)。
在这一行上,输入文件从 X+Y 列更改为 X 列。
外部 catch 首先被捕获并在内部 catch 自己完成之前停止程序。
我需要内部循环来捕获异常,因为我正在使用它将数据打印到文件中。
try{
Initialize local variables
//Includes getting numerical strings from input fields
//Hence NumberFormatException to check for correct input
try{
get file name
//hence FileNotFoundException
try{
read line, get column A, B and C
//Column B is at an index larger than X
//hence ArrayIndexOutOfBoundsException
}catch(ArrayIndexOutOfBoundsException){
print data to file
}
} catch(FileNotFoundException){
error message
}
} catch(NumberFormatException){
error message
//error caught here, checks for whether
//numbers were entered in the required fields
}
有没有办法强制内部捕获首先触发,或者代码是否需要重新处理?