If Multiple exceptions are allowed in catch() then it will reduce amount of redundant error handling code. for example,
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 */
}
Yes - that's why it's supported in Java 7.
So your example would actually be:
try {
} catch (Type1Exception | Type2Exception | Type3Exception ex) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With