Bird
0
0

Which of the following is the correct syntax to catch an error in PowerShell?

easy📝 Syntax Q12 of 15
PowerShell - Error Handling
Which of the following is the correct syntax to catch an error in PowerShell?
Acatch { Write-Host 'Error occurred' }
Bcatch() { Write-Host 'Error occurred' }
Ccatch: { Write-Host 'Error occurred' }
Dcatch[] { Write-Host 'Error occurred' }
Step-by-Step Solution
Solution:
  1. Step 1: Recall PowerShell catch syntax

    In PowerShell, catch is followed by a script block in curly braces without parentheses or other symbols.
  2. Step 2: Identify correct syntax

    catch { Write-Host 'Error occurred' } uses catch { ... } which is correct; others add invalid symbols like parentheses or colons.
  3. Final Answer:

    catch { Write-Host 'Error occurred' } -> Option A
  4. Quick Check:

    Correct catch syntax uses braces only = A [OK]
Quick Trick: Catch uses braces {} without parentheses [OK]
Common Mistakes:
  • Adding parentheses after catch
  • Using colon or brackets with catch
  • Missing curly braces around catch code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes