Bird
0
0

What will be the output of this PowerShell script?

medium📝 Command Output Q4 of 15
PowerShell - Error Handling
What will be the output of this PowerShell script?
try {
  Write-Output 'Begin'
  5 / 0
  Write-Output 'Finish'
} catch {
  Write-Output 'Exception caught'
} finally {
  Write-Output 'Finalizing'
}
A'Exception caught' then 'Finalizing' only
B'Begin' followed by 'Finish' then 'Finalizing'
C'Begin' followed by 'Exception caught' then 'Finalizing'
D'Begin' then 'Finalizing' only
Step-by-Step Solution
Solution:
  1. Step 1: Execution starts in try block

    'Begin' is output first.
  2. Step 2: Error occurs at 5 / 0

    Division by zero throws an exception, so 'Finish' is skipped.
  3. Step 3: catch block runs

    'Exception caught' is output.
  4. Step 4: finally block runs

    'Finalizing' is output regardless of error.
  5. Final Answer:

    'Begin' followed by 'Exception caught' then 'Finalizing' -> Option C
  6. Quick Check:

    Error skips rest of try, catch then finally run [OK]
Quick Trick: Error skips try remainder, catch then finally run [OK]
Common Mistakes:
  • Assuming 'Finish' runs after error
  • Thinking finally runs only on success
  • Missing catch block output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes