In a Java 7 multicatch block what is the type of the caught exception?

后端 未结 2 821
鱼传尺愫
鱼传尺愫 2020-11-28 14:19

In a Java 7 multicatch block such as the following:

try {
    // code that throws exception
} catch (CharacterCodingException | UnknownServiceException ex) {         


        
2条回答
  •  死守一世寂寞
    2020-11-28 14:53

    Yes, the type of ex is the most specific supertype of both CharacterCodingException and UnknownServiceException, which would be IOException.

    Edit: Straight from the horse's mouth on http://cr.openjdk.java.net/~darcy/ProjectCoin/ProjectCoin-Documentation-v0.83.html#multi_catch:

    Informally, the lub (least upper bound) is the most specific supertype of the types in question.

提交回复
热议问题