Hi, print statement after finally is showing unreachable statement error, but not showing in case after catch block. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Hi, print statement after finally is showing unreachable statement error, but not showing in case after catch block.

Why is it so?

17th Sep 2020, 6:35 AM
Nid
3 Réponses
+ 3
A finally statement doesn't catch exceptions thrown in the try block. Only catch statements can catch exceptions. Therefore, System.out.println("4"); is never reached, since the try block always throws an uncaught exception. Regarsds:stackoverflow
17th Sep 2020, 6:47 AM
Programmer ツ
Programmer ツ - avatar
+ 2
out. print("inside infinite loop"); code can never be reached with. When the compiler compiles the whole body of code and make byte code according to your code, it smarter enough to detectsunreachable code and also dead code. So, immediate break in the for-loop makes unreachable otherstatements.
17th Sep 2020, 6:38 AM
Programmer ツ
Programmer ツ - avatar
0
Yes, but it is not showing complition error when writing print statement after catch block. And showing when written after finally block. This all is happening inside a for loop with a break statement in a try block..? Pls explain.
17th Sep 2020, 6:43 AM
Nid