Bird
0
0

Which of the following is the correct syntax to throw an error with the message "Access denied" in PowerShell?

easy📝 Syntax Q3 of 15
PowerShell - Error Handling
Which of the following is the correct syntax to throw an error with the message "Access denied" in PowerShell?
Athrow "Access denied
Bthrow Access denied
Cthrow ("Access denied)
Dthrow 'Access denied'
Step-by-Step Solution
Solution:
  1. Step 1: Understand string quoting in PowerShell

    PowerShell supports single or double quotes for strings. Both are valid for messages.
  2. Step 2: Check syntax correctness

    throw Access denied is invalid because the message is not quoted. throw "Access denied" and throw ("Access denied") have unbalanced quotes causing syntax errors. throw 'Access denied' uses single quotes correctly.
  3. Final Answer:

    throw 'Access denied' -> Option D
  4. Quick Check:

    Throw with quoted string [OK]
Quick Trick: Always quote the error message string [OK]
Common Mistakes:
  • Not quoting the error message
  • Adding unnecessary parentheses
  • Using invalid syntax without quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes