下面的异常程序哪里出错?

class  FuShuException   extends   RuntimeException


{

FuShuException (String  msg)

{

super(msg);

}

}

class  Demo

{

int  div(int a, int  b)throws   Exception//throws  ArithmeticException

{

if(b<0)

throw  new   Exception("出现了除数为负数了");

if(b==0)

throw  new   ArithmeticException("被零除啦");

return  a/b;

}

}

class   ExceptionDemo4

{

public   static  void  main(String[]  args)

{

Demo  d=new  Demo();

int  x=d.div(4,-9);


System.out.println("x="+x);


System.out.println("over");

}

}

  


qq_丘比特_0
浏览 1446回答 3
3回答

晨光3138270

去RuntimeException副类找找原因

waste_time

你抛出了异常,需要catch一下,或者用throws声明啊
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java