Bird
0
0

What will be the output of this PowerShell script?

medium📝 Command Output Q13 of 15
PowerShell - Error Handling
What will be the output of this PowerShell script?
try {
  throw 'Error occurred'
  Write-Output 'This will not run'
} catch {
  Write-Output "Caught: $_"
}
AThis will not run
BError occurred
CNo output
DCaught: Error occurred
Step-by-Step Solution
Solution:
  1. Step 1: Understand throw inside try block

    The throw stops execution inside try and passes control to catch with the error message.
  2. Step 2: Check catch block output

    The catch block outputs "Caught: $_" where $_ contains the error message 'Error occurred'. So output is "Caught: Error occurred".
  3. Final Answer:

    Caught: Error occurred -> Option D
  4. Quick Check:

    throw in try triggers catch output = C [OK]
Quick Trick: throw inside try triggers catch block output [OK]
Common Mistakes:
  • Expecting code after throw to run
  • Ignoring catch block output
  • Confusing error message with direct output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes