class MyException extends Exception{
String message;
public MyException(String Errormessagr){
message = Errormessagr;
}
public String getMessagr(){
return message;
}
}
public class Captor{
static int quotien(int x, int y) throws MyException{
if(y < 0){
throw new MyException("除数不能为负数");
}
return x / y;
}
public static void main(String args[]){
try{
int result = quotien(3, -9);
}catch(MyException e){
System.out.print(e.getMessage());
}catch(ArithmeticException e){
System.out.print("除数不能为0");
}catch(Exception e){
System.out.print("程序发生了其他异常");
}
}
}
疑问:为啥结果输出null,而不是我想要的除数不能为负数?
|