Challenge - 5 Problems
Error Mastery in PowerShell
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
Identify the error type from output
What type of error does the following PowerShell command produce?
Get-Item 'C:\nonexistentfile.txt'
PowerShell
Get-Item 'C:\nonexistentfile.txt'Attempts:
2 left
💡 Hint
Think about whether the command stops execution or continues after the error.
✗ Incorrect
Get-Item produces a terminating error if the item does not exist, stopping execution unless handled.
💻 Command Output
intermediate1:30remaining
Recognize non-terminating error behavior
What happens when you run this command?
Get-ChildItem 'C:\nonexistentfolder' -ErrorAction Continue
PowerShell
Get-ChildItem 'C:\nonexistentfolder' -ErrorAction ContinueAttempts:
2 left
💡 Hint
Consider the effect of -ErrorAction Continue on errors.
✗ Incorrect
Get-ChildItem produces a non-terminating error if the folder does not exist and continues execution.
🔧 Debug
advanced2:00remaining
Why does this script stop on error?
Given this script:
Why does the script stop before printing 'Script continues'?
try {
Get-Item 'C:\nonexistentfile.txt' -ErrorAction Stop
}
Write-Output 'Script continues'Why does the script stop before printing 'Script continues'?
PowerShell
try {
Get-Item 'C:\nonexistentfile.txt' -ErrorAction Stop
}
Write-Output 'Script continues'Attempts:
2 left
💡 Hint
Think about how try-catch handles terminating errors.
✗ Incorrect
Get-Item with -ErrorAction Stop throws a terminating error. Without a catch block, the script stops.
📝 Syntax
advanced1:30remaining
Which command causes a terminating error?
Which of these commands causes a terminating error in PowerShell?
Attempts:
2 left
💡 Hint
Look for commands with -ErrorAction Stop on missing items.
✗ Incorrect
Remove-Item with -ErrorAction Stop throws a terminating error if the item does not exist.
🚀 Application
expert2:00remaining
Handling non-terminating errors as terminating
You want to treat non-terminating errors as terminating to stop the script on any error. Which command achieves this?
Get-ChildItem 'C:\nonexistentfolder' ???
Attempts:
2 left
💡 Hint
Which ErrorAction makes non-terminating errors behave like terminating ones?
✗ Incorrect
Using -ErrorAction Stop converts non-terminating errors into terminating errors, stopping the script.