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 exceptions. However, Oracle sources don't seem to name this feature anywhere, while some other sources (like Eclipse and SO) call it a "multi-catch" block.

Is there an official, Oracle-given name for this feature anywhere?


回答1:


The Java Language Specification section 14.20 refers to uni-catch and multi-catch clauses, which is about as official as it gets.

A catch clause whose exception parameter is denoted as a single class type is called a uni-catch clause.

A catch clause whose exception parameter is denoted as a union of types is called a multi-catch clause.

Of course, prior to Java 7 there were no multi-catch clauses, so the term "uni-catch" was never necessary until multi-catch was introduced.

The term multi-catch is distinct from having more than one (several, multiple) catch clauses.



来源:https://stackoverflow.com/questions/30114234/is-there-an-official-name-for-java-7s-combined-multi-catch-block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!