Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何仅打印异常名称?_Java_Exception - Fatal编程技术网

Java 如何仅打印异常名称?

Java 如何仅打印异常名称?,java,exception,Java,Exception,当用户插入2147483648作为x的输入时,会打印java.util.InputMismatchException:For input string:2147483648 Exception。但是我只需要打印java.util.InputMismatchException。怎么做?更换 try { Scanner input = new Scanner(System.in); int x = input.nextInt(); } catch (InputMismatchExce

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

更换

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

替换

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


System.out.printlnjava.util.InputMismatchException;你为什么要这么做?知道异常名称有什么用?Hackerrank problemSystem.out.printlnjava.util.InputMismatchException;你为什么要这么做?知道异常名称有什么用?黑客问题
System.out.println(g.getClass().getName());