黑马程序员技术交流社区
标题:
异常??求解??不同一个??
[打印本页]
作者:
高昌德
时间:
2014-12-5 20:39
标题:
异常??求解??不同一个??
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);进行处理了,编译还是提示要进行异常处理?
作者:
kerner
时间:
2014-12-5 21:21
int x = d.div(5,1);抛出三个异常,而你自己只处理了2个,Exception没有处理。
作者:
禾青青
时间:
2014-12-9 23:38
每天都来看一看
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2