Bird
0
0

Which statement about the $Error variable is true?

easy📝 Conceptual Q2 of 15
PowerShell - Error Handling
Which statement about the $Error variable is true?
A$Error only stores the last error that occurred
B$Error clears automatically after each command
C$Error stores errors in a stack with the most recent first
D$Error stores only syntax errors
Step-by-Step Solution
Solution:
  1. Step 1: Recall $Error behavior

    $Error stores errors in a collection where the most recent error is at the front (index 0).
  2. Step 2: Evaluate each option

    $Error stores errors in a stack with the most recent first correctly states the stack-like behavior. $Error only stores the last error that occurred is wrong because $Error stores multiple errors. $Error clears automatically after each command is false; $Error does not clear automatically. $Error stores only syntax errors is incorrect; $Error stores all error types.
  3. Final Answer:

    $Error stores errors in a stack with the most recent first -> Option C
  4. Quick Check:

    $Error = stack of errors, newest first [OK]
Quick Trick: Newest error is always at $Error[0] in the error stack [OK]
Common Mistakes:
  • Assuming $Error holds only one error
  • Believing $Error clears after each command

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes