0
0
PowerShellscripting~10 mins

Terminating vs non-terminating errors in PowerShell - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Terminating vs non-terminating errors
Run Command
Error Occurs?
NoContinue Execution
Yes
Is Error Terminating?
NoShow Error, Continue
Yes
Stop Execution Immediately
The script runs a command, checks if an error occurs, then decides if it stops or continues based on error type.
Execution Sample
PowerShell
Get-Item 'C:\NoSuchFile.txt'
Write-Output 'This runs after non-terminating error'

Get-Item 'C:\NoSuchFile.txt' -ErrorAction Stop
Write-Output 'This does NOT run after terminating error'
Shows a non-terminating error that allows script to continue, then a terminating error that stops the script.
Execution Table
StepCommandError Occurs?Error TypeAction TakenOutput
1Get-Item 'C:\NoSuchFile.txt'YesNon-terminatingShow error, continueError message displayed
2Write-Output 'This runs after non-terminating error'NoN/ARuns normallyThis runs after non-terminating error
3Get-Item 'C:\NoSuchFile.txt' -ErrorAction StopYesTerminatingStop executionError message displayed
4Write-Output 'This does NOT run after terminating error'NoN/ADoes NOT run
💡 Execution stops at step 3 due to terminating error triggered by -ErrorAction Stop
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
ErrorStatenullNon-terminating error recordedCleared after outputTerminating error triggeredScript stopped
Key Moments - 3 Insights
Why does the script continue after the first Get-Item command even though an error occurs?
Because the error is non-terminating by default, PowerShell shows the error but continues running the next commands as shown in execution_table step 1 and 2.
What causes the script to stop after the second Get-Item command?
The -ErrorAction Stop parameter makes the error terminating, so PowerShell stops execution immediately as shown in execution_table step 3.
Does the Write-Output command after the terminating error run?
No, it does not run because the script stops at the terminating error, as shown in execution_table step 4 where output is empty.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what type of error occurs at step 1?
ANon-terminating error
BTerminating error
CNo error
DSyntax error
💡 Hint
Check the 'Error Type' column in execution_table row for step 1
At which step does the script stop running commands?
AStep 2
BStep 4
CStep 3
DScript never stops
💡 Hint
Look at the 'Action Taken' and 'Output' columns in execution_table for step 3 and 4
If the -ErrorAction Stop was removed from step 3, what would happen?
AScript would stop at step 3
BScript would continue to step 4
CNo error would occur
DScript would crash
💡 Hint
Refer to how non-terminating errors behave in execution_table steps 1 and 2
Concept Snapshot
Terminating errors stop script immediately.
Non-terminating errors show message but continue.
Use -ErrorAction Stop to make errors terminating.
Default errors are non-terminating.
Check error type to control script flow.
Full Transcript
This lesson shows the difference between terminating and non-terminating errors in PowerShell. When a command causes a non-terminating error, PowerShell shows the error but keeps running the script. When a terminating error happens, PowerShell stops the script immediately. Using -ErrorAction Stop forces an error to be terminating. The example runs Get-Item on a missing file twice: first without stopping, then with stopping. The output and script flow change accordingly.