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());