import java.util.*;
public class Test {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
try {
System.out.println("请输入第一个数字:");
int a = sc.nextInt();
System.out.println("请输入第二个数字:");
int b = sc.nextInt();
System.out.println(ecm(a, b));
} catch (InputMismatchException e) {
System.out.println("数据类型不一致!");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("缺少命令行参数!");
} catch (EcDef e) {
System.out.println(e.getMessage());
}
}
//两数相除
public static int ecm(int a, int b) throws EcDef {
if (b == 0) {
throw new EcDef();
}
return a / b;
}
}
//异常类
class EcDef extends Throwable {
public EcDef() {
super("异常信息:被除数不能为0");
}
}
自定义异常
最新推荐文章于 2019-12-06 15:49:26 发布