multi-catch

Is there an official name for Java 7's combined / multi-catch block?

自古美人都是妖i 提交于 2019-12-08 15:52:08
问题 Upon discussing the multiple-catch / combined catch block here with ambiguity between the terms "multiple catch block," meaning the Java 7 feature: try { .. } catch (ExceptionA | ExceptionB ex) { .. } and "multiple catch blocks," meaning literally, multiple catch blocks: } catch (ExceptionA exa) { .. } catch (ExceptionB exb) { .. } I've researched to see if the Java 7 feature has a specific, official name that can be used to clearly distinguish it from the older style of catching multiple

reference type of exception issue in multi-catch block

别等时光非礼了梦想. 提交于 2019-12-02 06:04:57
问题 e is of type Exception but prints Exception1 in below code: 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 type Exception" System.out.println(e); //prints Exception1 (after commenting line 1) } } } From

reference type of exception issue in multi-catch block

主宰稳场 提交于 2019-12-02 01:52:14
e is of type Exception but prints Exception1 in below code: 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 type Exception" System.out.println(e); //prints Exception1 (after commenting line 1) } } } From what I studied "e" should be of type Exception which is common base class of Exception1 and Exception2.

Not able to use Multi Catch from Java Effectively [duplicate]

流过昼夜 提交于 2019-12-01 04:07:17
This question already has an answer here: What is a NumberFormatException and how can I fix it? [duplicate] 9 answers Why does order matter when catching exceptions? 8 answers I really want to use features from Java-1.7. One of this feature is "Multi-Catch". Currently I have the following code try { int Id = Integer.parseInt(idstr); TypeInfo tempTypeInfo = getTypeInfo(String.valueOf(Id)); updateTotalCount(tempTypeInfo); } catch (NumberFormatException numExcp) { numExcp.printStackTrace(); } catch (Exception exception) { exception.printStackTrace(); } I want to remove the two catch blocks from

Not able to use Multi Catch from Java Effectively [duplicate]

不羁的心 提交于 2019-12-01 01:41:39
问题 This question already has answers here : What is a NumberFormatException and how can I fix it? [duplicate] (9 answers) Why does order matter when catching exceptions? (8 answers) Closed 3 years ago . I really want to use features from Java-1.7. One of this feature is "Multi-Catch". Currently I have the following code try { int Id = Integer.parseInt(idstr); TypeInfo tempTypeInfo = getTypeInfo(String.valueOf(Id)); updateTotalCount(tempTypeInfo); } catch (NumberFormatException numExcp) { numExcp

Maven project Error: Diamond/multicatch operator not supported in -source 1.5 [duplicate]

风格不统一 提交于 2019-11-29 18:27:14
问题 This question already has an answer here: Maven Compilation Error: (use -source 7 or higher to enable diamond operator) 4 answers I can't build my maven java web application, because of the following two errors: 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) I'm confused, because i use java 1.8.0 for my project, i never have

Can I catch multiple Java exceptions in the same catch clause?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 00:39:21
问题 In Java, I want to do something like this: try { ... } catch (/* code to catch IllegalArgumentException, SecurityException, IllegalAccessException, and NoSuchFieldException at the same time */) { someCode(); } ...instead of: try { ... } catch (IllegalArgumentException e) { someCode(); } catch (SecurityException e) { someCode(); } catch (IllegalAccessException e) { someCode(); } catch (NoSuchFieldException e) { someCode(); } Is there any way to do this? 回答1: This has been possible since Java 7