public class UsingException {
public static void main(String[] args) {
try {
method();
}
catch(Exception e) {
System.out.print('m');
}
System.out.print('n');
}
static void method(){
try {
createException();
System.out.print('a');
}
catch(ArithmeticException e) {
System.out.print('b');
}
finally {
System.out.print('c');
}
System.out.print('d');
}
static void createException() {
throw new ArrayIndexOutOfBoundsException();
}
}
为什么输出CMN呢,我想知道为什么d没有输出啊,
因为把异常抛出了。
method()方法中,调用了createException();方法
throw new ArrayIndexOutOfBoundsException();
直接抛出了,所以后面的不会执行。
try代码块执行时如果有异常,会自动执行catch代码块,进行错误处理
finally运行结束整个就结束了,后面的不执行。怎么会输出N呢?