Java 一个catch块中有多种不同类型的异常处理?

Java 一个catch块中有多种不同类型的异常处理?,java,Java,如果catch()中允许多个异常,那么它将减少冗余错误处理代码的数量。 比如说, try{ // some statments } catch(Type1Exception t1, Type2Exception t2, Type3Exception t3) { // wish if this could be allowed /* t1, t2, t3 are children of Exception and needs same error handling then why to h

如果catch()中允许多个异常,那么它将减少冗余错误处理代码的数量。 比如说,

try{
// some statments 
}
catch(Type1Exception t1, Type2Exception t2, Type3Exception t3) {   // wish if this could be allowed
/* t1, t2, t3 are children of Exception and needs same error handling then why to have different catch blocks with same piece of code */
}
是的,这就是为什么它是

所以你的例子实际上是:

try {
} catch (Type1Exception | Type2Exception | Type3Exception ex) {
   ...
}

@拉近距离:我真的不理解人们投票结束一个问题,因为他们看不到一个问号!来吧,这是一个有趣的问题@阿门:现在还不清楚真正的问题是什么。另一方面,我希望我的回答能解决任何问题。…@Eng.Fouad:不,他的意思是
|
:-)该教程说:“在catch子句中,指定block可以处理的异常类型,并用竖线(|)分隔每个异常类型。”@Jon Skeet:在.NET(上一版本或下一版本)中是否有类似的内容?@VoodooChild:这将是一种语言功能,而不是平台功能。不过,我不知道在任何.NET语言中有任何等价物。@Jon Skeet我不知道Java 7的这个特性。进步很大@乔恩·斯基特:什么类型的
ex
?你提供的链接中没有提到它,但我想它是一个普通的超级类型?或者只是
异常
,或者
可丢弃