为什么我手动抛出的异常,不显示
来源:2-1 包装类与基本数据类型
軍度
2022-04-03 10:52:20
package cn.bhu.test;
import java.util.InputMismatchException;
import java.util.Scanner;
public class TryDemoOne {
public static void main(String[] args) {
TryDemoOne one=new TryDemoOne();
one.teat();
}
public void teat() {
System.out.println("程序开始执行");
Scanner sc=new Scanner(System.in);
try {
System.out.println("输入one");
int one=sc.nextInt();
System.out.println("输入two");
int two=sc.nextInt();
System.out.println("one和two的商为"+one/two);
throw new ArithmeticException("除数真的不能为0");
}catch (ArithmeticException e) {
System.out.println("除数不能为0");
e.printStackTrace();
}catch(InputMismatchException e){
System.out.println("请输入整数");
e.printStackTrace();
}
}
}
问题描述:
为什么我手动抛出的异常,不显示
2回答
好帮手慕小蓝
2022-04-04
同学你好,老师这里测试同学的代码,是可以正常显示异常的。如下图所示:
祝学习愉快~
吕小绿与红鲤鱼与绿鲤鱼与驴
2022-04-03
我运行了一下你的代码,可以正常显示异常啊~
相似问题