Control flow in try-catch:
Case 1: There is no exception.
1, 2, 3, 5 normal terminations.
Case 2: if an exception raised at statement 2 and corresponding catch block matched 1, 4, 5 normal terminations.
Case 3: if an exception raised at statement 2 but the corresponding catch block not matched 1 followed by abnormal termination.
Case 4: if an exception raised at statement 4 or statement 5 then it’s always abnormal termination of the program.
Note:
1. Within the try block if anywhere an exception raised then the rest of the try block won’t be executed even though we handled that exception. Hence we have to place/take only risk code inside try and length of the try block should be as less as possible.
2. If any statement raises an exception and it is not part of any try block then it is always abnormal termination of the program.
3. There may be a chance of raising an exception inside catch and finally blocks also in addition to try block
Comments
Post a Comment