- class MutiException
- {
- public static void main(String[] args)
- {
- try
- {
- System.out.println(div(4,1));
- }
- catch(ArithmeticException e)
- {
- System.out.println("haha" + e.toString());
- }
- catch(ArrayIndexOutOfBoundsException e)
- {
- System.out.println("heihei" + e.toString());
- }
-
- }
- static int div(int a,int b) throws Exception //为什么不能这么写?
- {
- int[] arr = new int[a];
- System.out.println(arr[3]);
- return a / b;
- }
- }
复制代码 编译时说:错误: 未报告的异常错误Exception; 必须对其进行捕获或声明以便抛出
|