class Demo
{
int div(int a,int b)throws ArithmeticException,ArrayIndexOutOfBoundsException
{
int arr[]=new int[a];
System.out.println(arr[4]);
return a/b;
}
}
class Demodemo8
{
public static void main(String[] args)
{
Demo d=new Demo();
try
{
int x=d.div(4,0);
System.out.println(x);
}
catch (ArithmeticException e)
{
e.printStackTrace();
System.out.println("除零了!!!");
}
catch(ArrayIndexOutOfBoundsException e)
{
e.printStackTrace();
System.out.println("角标越界!!!!!!!!!!");
}
}
}
//异常不可能全部一起发生,肯定有先后,谁写在前边谁先发生,谁就先处理,下面的不运行!!!
异常不可能全部同时发生
最新推荐文章于 2024-01-24 16:36:45 发布