如何仅打印异常名称?


try {
Scanner input = new Scanner(System.in);
int x = input.nextInt();
} catch (InputMismatchException g) {
System.out.println(g);
}

当用户将"2147483648"作为输入插入x时,将打印java.util.InputMismatchException: For input string: "2147483648"异常。但我只需要打印java.util.InputMismatchException。怎么做?

替换

System.out.println(g);

System.out.println(g.getClass().getName());

最新更新