Bird
0
0

What will this PowerShell script output?

medium📝 Command Output Q5 of 15
PowerShell - Error Handling
What will this PowerShell script output?
try {
  throw 'Oops'
} finally {
  Write-Output 'Cleanup done'
}
ACleanup done
BNo output
COops
DCleanup done Oops
Step-by-Step Solution
Solution:
  1. Step 1: Understand throw in try block

    The throw raises an error, so the script will terminate unless caught.
  2. Step 2: Understand finally block behavior

    The finally block always runs, so it outputs "Cleanup done" before the error propagates.
  3. Final Answer:

    Cleanup done Oops -> Option D
  4. Quick Check:

    Finally runs before error propagates [OK]
Quick Trick: Finally block runs even after throw [OK]
Common Mistakes:
  • Assuming finally skips on throw
  • Expecting only error message output
  • Ignoring finally block output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes