0
0
PowerShellscripting~20 mins

Terminating vs non-terminating errors in PowerShell - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Error Mastery in PowerShell
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1: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'
ATerminating error
BNon-terminating error
CNo error, outputs null
DSyntax error
Attempts:
2 left
💡 Hint
Think about whether the command stops execution or continues after the error.
💻 Command Output
intermediate
1: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 Continue
ASyntax error
BTerminating error, stops execution
CNo error, lists files
DNon-terminating error, continues execution
Attempts:
2 left
💡 Hint
Consider the effect of -ErrorAction Continue on errors.
🔧 Debug
advanced
2:00remaining
Why does this script stop on error?
Given this script:
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'
ABecause Get-Item throws a terminating error caught by catch, script continues after catch
BBecause Get-Item throws a terminating error but catch block is missing, script stops
CBecause Get-Item throws a terminating error caught by catch, script stops anyway
DBecause Get-Item throws a non-terminating error, script stops
Attempts:
2 left
💡 Hint
Think about how try-catch handles terminating errors.
📝 Syntax
advanced
1:30remaining
Which command causes a terminating error?
Which of these commands causes a terminating error in PowerShell?
AWrite-Output 'Hello World'
BGet-ChildItem 'C:\nonexistentfolder' -ErrorAction SilentlyContinue
CRemove-Item 'C:\nonexistentfile.txt' -ErrorAction Stop
DGet-Process 'nonexistentprocess' -ErrorAction Continue
Attempts:
2 left
💡 Hint
Look for commands with -ErrorAction Stop on missing items.
🚀 Application
expert
2: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' ???
A-ErrorAction Stop
B-ErrorAction Continue
C-ErrorAction SilentlyContinue
D-ErrorAction Ignore
Attempts:
2 left
💡 Hint
Which ErrorAction makes non-terminating errors behave like terminating ones?