Is there any alternative in java to make code possible in jdk1.6. I know same is possible in jdk 1.7, but i am stuck with jdk1.6.
Below code can catch multiple exceptions and i want to handle these exception and add it to database table. Since for all 3 exceptions, my exception handling logic is going to remain same. I don't want repeat same code for multiple catch blocks.
try{
//do somthing here
}catch(CustomException1 ex1 | CustomException2 ex2 | CustomException3 ex3){
// Here goes common Exception handing logic.
}
try{
//do somthing here
}catch(Exception e){
if(e instanceof CustomException1 || e instanceof CustomException2 || e instanceof CustomException3 ) {
// Here goes common Exception handing logic.
} else { throw e;}
}
There is no other option I think.
This syntax was added in Java 1.7 because it was difficult to do it cleanly before.
There are a few things you can do:
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