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:
Step 1: Recall $Error behavior
$Error stores errors in a collection where the most recent error is at the front (index 0).
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.
Final Answer:
$Error stores errors in a stack with the most recent first -> Option C
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
Master "Error Handling" in PowerShell
9 interactive learning modes - each teaches the same concept differently