Bird
0
0

Identify the error in this PowerShell script:

medium📝 Debug Q6 of 15
PowerShell - Error Handling
Identify the error in this PowerShell script:
try {
  Write-Output 'Test'
} catch
  Write-Output 'Error'
}
AMissing curly braces {} around catch block
BMissing try keyword
CExtra closing brace in try block
DNo error, script is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check catch block syntax

    Catch block must have curly braces {} to define its code block.
  2. Step 2: Identify missing braces

    The script lacks braces around catch's Write-Output statement, causing syntax error.
  3. Final Answer:

    Missing curly braces {} around catch block -> Option A
  4. Quick Check:

    catch block requires braces { } [OK]
Quick Trick: Always use braces {} for catch block code [OK]
Common Mistakes:
  • Omitting braces in catch
  • Misplacing closing braces
  • Confusing try and catch syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes