Bird
0
0

What will this PowerShell script output?

medium📝 Command Output Q4 of 15
PowerShell - Error Handling
What will this PowerShell script output?
try { Get-Content 'Z:\missingfile.txt' -ErrorAction Stop } catch { Write-Output 'Error caught' }
AThe content of the file
BNo output, script stops silently
CError caught
DAn unhandled error message
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the command

    Get-Content tries to read a non-existent file with -ErrorAction Stop, causing a terminating error.
  2. Step 2: Understand try-catch

    The terminating error triggers the catch block, which outputs 'Error caught'.
  3. Final Answer:

    Error caught -> Option C
  4. Quick Check:

    Terminating errors invoke catch block [OK]
Quick Trick: Terminating errors trigger catch blocks [OK]
Common Mistakes:
  • Expecting no output because of error
  • Assuming script stops without catch output
  • Thinking non-terminating errors trigger catch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes