+ 1

What will happen if you put return statement or System.exit () on try or catch block? Will finally block execute? Read more: ht

. This question challenge that concept by putting a return statement in the try or catch block or calling System.exit() from try or catch block

11th Apr 2020, 6:50 PM
ekhlas Mohamed Abdallah Mohamed
ekhlas Mohamed Abdallah Mohamed - avatar
2 Answers
+ 2
just return; statement from a method will goes to execute finally block. comes out of method.. And should write it properly.. But System.exit(0); Stops Program execution without finally executed... Try it in playground...... Except by the system calls, finally block executed..
11th Apr 2020, 10:09 PM
Jayakrishna 🇮🇳
+ similar situation if catch() throw Exception then finally will even be executed before throw
12th Apr 2020, 12:06 AM