Multiple choice technology programming languages

Which of the following options is true for the following program: try { if (choice) { while (true) } else { system .exit(1): } }finally { codetocleanup(); }

  1. Runtime Exception

  2. finally block will be executed

  3. finally block will not be executed

  4. Compilation error in else block

Reveal answer Fill a bubble to check yourself
C Correct answer
AI explanation

A finally block is guaranteed to run after the try block completes in any way — normal completion, an exception, or a return — but only if control actually leaves the try block. while(true) with no break is an infinite loop, so the thread never exits the try block and control never reaches finally, meaning codetocleanup() is never executed. This is a classic exception to the "finally always runs" rule.