1、格式
ArithmetricException("")
try(){
throw(ArithmetricException("");
}catch(){
//输出的异常捕获错误
}
2、举个
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数字");
int firstNum = sc.nextInt();
System.out.println("请输入第二个数字");
int secondNum =sc.nextInt();
try {
if (secondNum==0)
//可缺省
// throw new ArithmeticException("除数不能为0");
System.out.println("Result:"+"number1"+"/"+"number2"+"="+firstNum/secondNum);
}catch (ArithmeticException e){
System.out.println("Excption:error,除数不能为0");
}
System.out.println("相除的结果是:");
}<