Bird
0
0

Identify the error in this script snippet:

medium📝 Debug Q6 of 15
PowerShell - Error Handling
Identify the error in this script snippet:
try { Get-Item 'file.txt' } catch { Write-Host 'Error' } -ErrorAction Continue
A-ErrorAction Continue is invalid
B-ErrorAction should be inside try block
CCatch block cannot be used with try
DNo error, script is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check placement of -ErrorAction

    -ErrorAction must be part of the command that may error, inside try block.
  2. Step 2: Identify script error

    Here, -ErrorAction is outside try block, causing syntax error.
  3. Final Answer:

    -ErrorAction should be inside try block -> Option B
  4. Quick Check:

    -ErrorAction placement matters [OK]
Quick Trick: Put -ErrorAction with the command inside try block [OK]
Common Mistakes:
  • Placing -ErrorAction outside try
  • Misusing catch block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes