Tag: multi catch

多捕获块中的引用类型的exception问题

e的类型为Exception,但在下面的代码中打印Exception1: class Exception1 extends IOException {void info(){}} class Exception2 extends Exception {} class TestMultiCatch { public static void main(String args[]) { try { int a = 10; if (a <= 10) throw new Exception1(); else throw new Exception2(); } catch (Exception1 | Exception2 e) { e.info(); //line 1 error "The method info() is undefined for […]

无法有效地使用Java中的Multi Catch

我真的想使用Java-1.7的function。 其中一个function是“Multi-Catch”。 目前我有以下代码 try { int Id = Integer.parseInt(idstr); TypeInfo tempTypeInfo = getTypeInfo(String.valueOf(Id)); updateTotalCount(tempTypeInfo); } catch (NumberFormatException numExcp) { numExcp.printStackTrace(); } catch (Exception exception) { exception.printStackTrace(); } 我想从上面的代码中删除两个catch块,而是使用如下所示的单个catch: try { int Id = Integer.parseInt(idstr); TypeInfo tempTypeInfo = getTypeInfo(String.valueOf(Id)); updateTotalCount(tempTypeInfo); } catch (Exception | NumberFormatException ex) { // –> compile time error ex.printStackTrace(); } 但上面的代码给出了编译时错误: “NumberFormatException”已被替代Exception捕获。 […]

Maven项目错误:-source 1.5中不支持Diamond / multicatch运算符

由于以下两个错误,我无法构建我的maven java Web应用程序: diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator) multi-catch statement is not supported in -source 1.5 (use -source 7 or higher to enable multi-catch statement) 我很困惑,因为我使用java 1.8.0作为我的项目,我从来没有实际使用过1.5 什么可能导致这个问题,我该如何解决? 我在pom.xml中添加了以下行后尝试构建它,但没有成功: 1.8 1.8