package 异常课堂; import java.util.Scanner; public class 数字异常 { public static void main(String[] args) { System.out.println("请输入数字"); try { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); } catch (Exception ex) { System.out.println("请输入正确的数字" + ex.getMessage()); ex.printStackTrace(); } } }
运行结果