栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

多捕获块中异常问题的引用类型

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

多捕获块中异常问题的引用类型

当您使用 多catch子句 (的

Exception1 | Exception2e
形式
catch
),在编译时类型
e
是最大的类型两种类型的共同点,因为课程的代码必须处理两种类型exception.From的规范:

异常参数可以将其类型表示为单个类类型或两个或多个类类型的并集(称为替代)。联合的选择在句法上用分隔

|

将异常参数表示为单个类类型 的catch子句 称为 uni-catch子句

一个其异常参数表示为类型并集的 catch子句 称为 multi-catch子句

异常参数的声明类型为,表示其类型为与替代的

D1 | D2 | ... | Dn
并集
lub(D1, D2, ..., Dn)

…其中

lub
定义的最小上界这里。

如果您想使用特定于

Exception1
或的任何内容
Exception2
,请使用单独的
catch
块:

} catch (Exception1 e) {    // Something using features of Exception1} catch (Exception2 e) {    // Something using features of Exception2}

如果和

info
同时存在,则对其进行重构,以使其存在于它们的共同祖先类中:
Exception1``Exception2``info

class TheAncestorException extends Exception {    public void info() { // Or possibly make it abstract        // ...    }}class Exception1 extends TheAncestorException {    // Optionally override `info` here}class Exception2 extends TheAncestorException {    // Optionally override `info` here}

…因此编译器可以指定

e
类型
TheAncestorException
并使其
info
可访问。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/428767.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号