I have very simple question. I am not using it but I have curiosity to know the answer. Can we execute multiple statements in catch block only if the exception get catched? I mean in my code below will both statement will get executed or not? Let me add some code snippet to make it clear..
I have found this link but not giving me the answer to my question.
link Click Here
The above link I found in this question asked by someone but It has very blurry code so hard to understand.
stackoverflow Link
try {
int x = doXProcess();
int y = doYProcess();
} catch (Exception e) {
System.out.println("Error related x: " x + e.printStackTrace());
System.out.println("Error related y: " y + e.printStackTrace());
}
Thanks you for your help and time.
It is common to see multiple statements in a
tryblock.If an exception occurs on the first line, the second line is not executed. Execution stops on any line where an exception is thrown; no lines past that point in the block are executed — execution proceeds directly to the catch block.
If an exception is thrown from the
catchblock, execution again stops at the line on which the exception occurred. From there you go to afinallyblock, if one is defined.