📄 exceptiondemo1.java
字号:
import java.io.*;
public class ExceptionDemo1{
public static void main(String[] args){
try{
ExceptionDemo1 ed = new ExceptionDemo1();
ed.Demo(args);
}
catch(MyException4 e3){
System.out.println("MyException4被捕获!");
}
catch(MyException2 e4){
System.out.println("MyException2被捕获!");
}
finally{
System.out.println("finally语句被执行!");
}
}
public void Demo(String[] args) throws MyException2,MyException4{
try{
int len = args.length;
System.out.println("\n Len = " + len);
int b = 42/len;
int[] c = {1};
c[42]=99;
}
catch(ArithmeticException e1){
throw new MyException2();//抛出自定义异常类的一个对象
}
catch(IndexOutOfBoundsException e2){
throw new MyException4();//抛出自定义异常类的一个对象
}
catch(Exception e5){
System.out.println("发生了异常!" + e5);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -