Say, I have a function which can throw 3 types of exceptions e1, e2, and e3. So, in this function there are 2 ways of handling the exception. Which is the better way and why? Example:-
public void func() {
block1 starts
block1 ends
e1 can thrown from block1
block2 starts
block2 ends
e2 can thrown from block2
block3 starts
block3 ends
e3 can thrown from block3
}
So, now I can handle the exceptions in 2 ways:- 1. Put 3 different try catch for 3 different blocks. 2. Put a single try on all 3 blocks and have 3 catch for each exception.
Which is considered a better way to do this?