In a Java 7 multicatch block what is the type of the caught exception?(在 Java 7 多捕获块中,捕获的异常的类型是什么?)
问题描述
在 Java 7 多捕获块中,如下所示:
In a Java 7 multicatch block such as the following:
try {
// code that throws exception
} catch (CharacterCodingException | UnknownServiceException ex) {
// handle exception
}
ex
的编译时类型是什么?它是两种异常类型共有的最派生类吗?在此示例中,这将是一个 IOException
.
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
.
推荐答案
是的,ex
的类型是 CharacterCodingException
和 UnknownServiceException 最具体的超类型
,即 IOException
.
Yes, the type of ex
is the most specific supertype of both CharacterCodingException
and UnknownServiceException
, which would be IOException
.
直接从马嘴里http://cr.openjdk.java.net/~darcy/ProjectCoin/ProjectCoin-Documentation-v0.83.html#multi_catch:
非正式地,lub(最小上限)是所讨论类型中最具体的超类型.
Informally, the lub (least upper bound) is the most specific supertype of the types in question.
这篇关于在 Java 7 多捕获块中,捕获的异常的类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Java 7 多捕获块中,捕获的异常的类型是什么


基础教程推荐
- Struts2 URL 无法访问 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01