- class Demo
- {
- public int div(int a,int b)throws ArithmeticException,ArrayIndexOutOfBoundsException,Exception
- {
- int[] arr = new int[a];
- System.out.println(arr[5]);
- return a/b;
- }
- }
- public class ExceptionDemo {
- public static void main(String[] args)
- {
- Demo d = new Demo();
- try
- {
- int x = d.div(5,1);
- System.out.println(x);
- }
- catch(ArithmeticException e)
- {
- System.out.println("除0了");
- System.out.println(e.toString());
- }
- catch(ArrayIndexOutOfBoundsException e1)
- {
- System.out.println("角标越界了");
- System.out.println(e1.toString());
- }
- System.out.println("over");
- }
- }
复制代码 为什么已经对int x = d.div(5,1);进行处理了,编译还是提示要进行异常处理?
|
|