I have the following situation:
try{
}
catch(SomeException ex){
doSomething();
}
catch(SomeOtherException ex){
doSomething();
}
catch(AndYetAnotherException ex){
doSomething();
}
catch(Exception ex){
}
In Java v7 +, I can change this to:
try{
}
catch(SomeException | SomeOtherException | AndYetAnotherException ex){
doSomething();
}
catch(Exception ex){
}
Since Android does not yet support Java 7+, I cannot use the above. What are the risks in the following:
try{
}
catch(Exception ex){
if(ex instanceof SomeException || ex instanceof SomeOtherException || ex instanceof AndYetAnotherException){
doSomething();
}
else{
}
}
I do not have enough experience or knowledge, so I do not know the risks. Are there any unexpected results? Are there any performance changes at runtime and / or at compile time? and etc.
If there are no risks, high performance changes or unexpected results, then why not use instanceof for one catch? If there is any risk, I think it's better to use a few catches that are better supported by both Android / Java itself and compilation behind the scenes.