在Java 7的多块块中,捕获的异常的类型是什么? [英] In a Java 7 multicatch block what is the type of the caught exception?
问题描述
try {
//引发异常的代码
} catch(CharacterCodingException | UnknownServiceException ex){
// handle exception
}
ex
的编译时类型是什么?这是两个异常类型有最常见的派生类吗?在这个例子中,这将是一个 IOException
。
是的, ex
的类型是 CharacterCodingException
和 UnknownServiceException
,这将是 IOException
。
编辑:直接从马的嘴在 http://cr.openjdk.java .net /〜darcy / ProjectCoin / ProjectCoin-Documentation-v0.83.html#multi_catch :
非常地, (最小上限)是所讨论类型的最具体的超类型。
In a Java 7 multicatch block such as the following:
try {
// code that throws exception
} catch (CharacterCodingException | UnknownServiceException ex) {
// handle exception
}
what is the compile-time type of ex
? Is it the most derived class that both exception types have in common? In this example that would be an IOException
.
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.
这篇关于在Java 7的多块块中,捕获的异常的类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!