First lets asume, doSomething1() and exceltion_handle1(), don't call System.exit(x) or something.
1) So first piece of code, will doSomething1(), no matter doSomething1() will throw any Exception or not, it will handle it (process the catch code block) and advance to second try and run it the same way.
try {
doSomething1();
} catch(Exception e1){
exception_handle1();
}
try {
doSomething2();
} catch(Exception e2){
exception_handle2();
}
It's morning, so I hope I won't make any wrong decisions.
2) This code will run doSomething1() then doSomething2(), and no matter which one will fail (throw Exception), only first catch clause will be called, as it absorbs all the subclasses and itself, so second catch won't be reached (first takes all the possible exceptions).
So afaik, you should get an error (shouldn't compile). It's smart and will recognize, that second catch won't be reached in any way.
The correct pattern would be : as we go to the bottom, exceptions should be broader and broader (strictly). It's logical, as order of catching clauses goes down, upper catch shouldn't be parent of bottom ones, as ANYWAY parent will take that exception, and childs in the bottom won't be reached.
Example: (I recommend you to learn about Multicatch in java.)
catch (Specific2ChildOfSpecific1 e3)
...
catch (specific1ChildOfException e2)
...
catch (Exception e1)
try {
doSomething1();
doSomething2();
} catch(Exception e1) {
exception_handle1();
} catch(Exception e2) {
exception_handle2();
}
3) This one: If doSomething1() will fail e1 catch clause will be executed and thats all, if it will pass, then if doSomething2() will run and if it fails, then e2 catch clause will be executed.
Notice @ second example, no matter which doSomething will fail, e1 will be executed (don't forget there is an error as second is unreachable). But I understand what you wanted to ask.
try {
doSomething1();
try {
doSomething2();
} catch(Exception e2){
exception_handle2();
}
} catch(Exception e1){
exception_handle1();
}