Write-Error writes an error message to PowerShell’s error stream.
By default, it creates a non-terminating error. That means PowerShell displays the error, but usually continues with the next command.
Write-Error "The file could not be found."
Write-Output "The script continued."
Typical result:
Write-Error: The file could not be found.
The script continued.
Make it terminating
Use:
-ErrorAction Stop
Example:
Write-Error "The file could not be found." -ErrorAction Stop
Write-Output "This line will not run."
Now the error stops normal execution.
Use with try/catch
try {
Write-Error "The server is unavailable." -ErrorAction Stop
}
catch {
Write-Warning "The error was caught."
Write-Warning $_.Exception.Message
}
Possible output:
WARNING: The error was caught.
WARNING: The server is unavailable.
Without -ErrorAction Stop, the catch block normally does not run because Write-Error is non-terminating by default.
Inside a function
function Get-LabFile {
param(
[string]$Path
)
if (-not (Test-Path -Path $Path)) {
Write-Error "The file '$Path' does not exist."
return
}
Get-Content -Path $Path
}
Call:
Get-LabFile -Path ".\missing.txt"
Error details
Write-Error can provide more structured information:
Write-Error `
-Message "The configuration file is missing." `
-Category ObjectNotFound `
-ErrorId "ConfigFileMissing" `
-TargetObject ".\config.json"
This creates an error record containing:
Message
Error category
Error ID
Target object
$Error
Errors written by Write-Error are normally stored in the automatic $Error variable.
Write-Error "Testing error storage"
$Error[0]
$Error[0] is the most recent error.
Write-Error versus throw
Write-Error "A problem occurred"
Non-terminating by default
Usually continues
Can be changed with -ErrorAction Stop
throw "A serious problem occurred"
Terminating
Stops execution immediately unless caught
Write-Error versus other output commands
Command
Purpose
Write-Output
Sends normal data to the success pipeline
Write-Warning
Displays a warning
Write-Verbose
Displays detailed information when -Verbose is used
Write-Error
Writes an error record
throw
Creates a terminating exception
A useful rule:
Use Write-Error when an operation has failed but the caller may decide whether execution should continue. Use throw when the operation cannot safely continue.
Terminating error vs non-terminating error in PowerShell
Non-terminating error
A non-terminating error reports a problem but allows PowerShell to continue running the remaining commands.
Example:
Get-Content -Path ".\MissingFile.txt"
Write-Output "The script continued."
Possible output:
Get-Content : Cannot find path '.\MissingFile.txt' because it does not exist.
The script continued.
The file-reading command failed, but PowerShell still ran the next line.
Common examples include:
Get-Content ".\MissingFile.txt"
Get-Item ".\MissingFolder"
Write-Error "A problem occurred"
By default, many PowerShell cmdlets generate non-terminating errors.
Terminating error
A terminating error stops the current operation or script block. PowerShell does not continue normally unless the error is caught.
Example using throw:
throw "The configuration file is invalid."
Write-Output "This line will not run."
The second command does not run because throw creates a terminating error.
Another example:
$result = 10 / 0
Write-Output "Finished"
Division by zero produces a terminating error.
Main difference
Feature
Non-terminating error
Terminating error
Displays an error
Yes
Yes
Continues to the next command
Usually yes
No
Automatically activates catch
No
Yes
Can be converted using -ErrorAction Stop
Yes
Already terminating
Typical source
Cmdlet failure
throw, runtime failure, or -ErrorAction Stop
Why try/catch sometimes does not work
Consider:
try {
Get-Content -Path ".\MissingFile.txt"
}
catch {
Write-Output "The error was caught."
}
You might expect catch to run, but Get-Content normally produces a non-terminating error.
Therefore, PowerShell displays the error but may not enter the catch block.
To make it catchable, add:
-ErrorAction Stop
Correct version:
try {
Get-Content -Path ".\MissingFile.txt" -ErrorAction Stop
}
catch {
Write-Output "The file could not be read."
}
Now the non-terminating error is converted into a terminating error, so catch runs.
Full example
try {
Write-Output "Trying to read the file..."
$content = Get-Content `
-Path ".\MissingFile.txt" `
-ErrorAction Stop
Write-Output "The file was read successfully."
}
catch {
Write-Warning "The file could not be read."
Write-Warning "Reason: $($_.Exception.Message)"
}
finally {
Write-Output "The operation is complete."
}
Expected output:
Trying to read the file...
WARNING: The file could not be read.
WARNING: Reason: Cannot find path ...
The operation is complete.
The finally block runs whether the operation succeeds or fails.
ErrorAction values
Many cmdlets support the common parameter -ErrorAction.
Answer: Probably no — quality was not truly built in.
The team may have done some testing, but the result shows that quality was not built into the full process.
Why?
Because:
Evidence
What it suggests
Checkout crashes 40% of the time
Critical functionality was not properly tested.
Password reset fails
Important user flow was missed.
Buttons do not respond on mobile
Mobile/responsive testing was missing.
All stories were marked Done
The Definition of Done was probably weak.
Automated tests passed
The automated tests did not cover the right scenarios.
Teaching explanation
You can tell students:
“If all stories were marked Done and automated tests passed, but customers still experience major failures, then the team did not build quality deeply enough into the process. They may have tested something, but not the right things.”
What was missing?
Likely missing items:
Missing quality practice
Example
Strong Definition of Done
Story cannot be Done unless tested on desktop and mobile.
Better acceptance criteria
Checkout must work successfully for valid payment, failed payment, and mobile checkout.
End-to-end testing
Test the complete user journey: login → order food → checkout → confirmation.
Mobile testing
Buttons and screens must work on common mobile screen sizes.
Regression testing
Existing features like password reset must still work after new changes.
Exploratory testing
Humans try unusual cases that automation may miss.
Best short classroom answer
No, quality was not truly built in. The team had a “Done” label and automated tests, but the tests and DoD were incomplete. Built-in quality means the team prevents defects through strong acceptance criteria, testing, review, mobile checks, and Definition of Done before the work is released.
A good discussion follow-up:
“What should be added to the Definition of Done so this problem does not happen again?”
Yes. Debrief means the short discussion after the activity.
After students finish the RCA/Fishbone/Five Whys activity, you ask them to share what they found.
Meaning of this line
One group shares one strong DoD item
It means:
Each group should give one good Definition of Done checklist item that could prevent this problem from happening again.
Example classroom instruction
You can say:
“Now we will debrief. Each group, please share one strong Definition of Done item that would have prevented the checkout crash or mobile button issue.”
Strong DoD examples students may give
Weak DoD item
Strong DoD item
“Testing completed”
“Checkout must be tested successfully on desktop and mobile before the story is marked Done.”
“Code works”
“All acceptance criteria must pass, including happy path and error cases.”
“Reviewed by team”
“Code review and QA review must be completed before moving to Done.”
“UI completed”
“UI buttons must be tested on common mobile screen sizes.”
Best example answer
A strong DoD item would be:
A user story cannot be marked Done unless it passes functional testing on both desktop and mobile, all acceptance criteria are verified, and no critical defects remain open.
How to explain debrief to students
“Debrief means we stop the group work and learn from each other. We are not only checking the answer. We are asking: what did your group discover, and how would you improve the process next time?”
Fishbone helps find the root cause by organizing possible causes into categories, so the team does not jump to one quick answer or blame one person too early. It is a visual RCA tool used to identify possible causes of a problem.
Simple explanation for students
“Fishbone does not automatically give the root cause. It helps the team brainstorm, organize, compare, and narrow down possible causes until the most likely root cause becomes visible.”
How it works
Problem:
Checkout crashes 40% of the time
Fishbone categories:
People --------\
Process --------\
Tools -----------> PROBLEM: Checkout crashes 40% of the time
Testing --------/
DoD ------------/
Environment ---/
Then the team asks:
Category
Possible causes
People
Developer rushed, reviewer missed issue
Process
No mobile testing step, weak release checklist
Tools
Automated tests did not catch checkout crash
Testing
Only happy-path testing, no edge-case testing
Definition of Done
Story marked Done without mobile validation
Environment
Test environment different from production
How it leads to the root cause
After listing possible causes, the team looks for the causes that are most likely, most repeated, or supported by evidence.
For example, the team may discover:
The checkout failed mostly on mobile devices, but mobile testing was not part of the Definition of Done.
So the root cause may be:
The team’s Definition of Done did not require mobile checkout testing before release.
Teaching line
Fishbone helps us move from “What went wrong?” to “What could have caused it?” and then to “Which cause should we fix so the problem does not happen again?”
Yes. Fishbone Analysis should usually be shown as a diagram, because it is a visual Root Cause Analysis tool. It is also called an Ishikawa Diagram or Cause-and-Effect Diagram. Your slide defines it as a visual tool for identifying possible causes of a specific problem.
Simple Fishbone Diagram Example
Problem:
Checkout crashes 40% of the time
People
Not enough QA training
No reviewer assigned
\
\
Process ------------------------\
No mobile test checklist \
No release approval step \
\
Tools -----------------------------> PROBLEM:
Test automation missed mobile Checkout crashes
No crash-monitoring tool 40% of the time
/
Testing --------------------------/
Only happy-path tests
No stress / edge-case tests
/
Definition of Done -------------/
AC checked, but mobile testing missing
Security/performance not checked
/
Environment -------------------/
Different mobile browsers
Production data different from test data
How to explain it to students
“The fish head is the problem. The bones are major cause categories. Under each bone, we write possible causes. We are not choosing the final answer immediately. First, we brainstorm possible causes. Then we analyze which causes are most likely to be the real root cause.”
Cleaner classroom version
People --------\
Process --------\
Tools -----------> PROBLEM: Checkout crashes 40% of the time
Testing --------/
DoD ------------/
Environment ---/
Then students add details under each category.
Example causes
Category
Possible causes
People
Developer rushed, reviewer missed issue, QA not involved early
Process
No mobile testing step, weak release checklist
Tools
Automated tests did not cover checkout crash
Testing
Only normal cases tested, no edge cases
Definition of Done
Story marked Done without mobile validation
Environment
Production data/browser/device different from test environment
Teaching line
Fishbone helps the team avoid blaming one person too quickly. It shows that quality problems usually come from multiple causes: people, process, tools, testing, and environment.
Work is started only when the next person or stage has capacity.
It is the opposite of a push system, where managers or upstream teams keep assigning work even when people are already overloaded.
Simple explanation
System
Meaning
Problem / Benefit
Push system
Work is pushed to people whether they have capacity or not.
Creates overload, multitasking, bottlenecks.
Pull system
Team members pull new work only when they are ready.
Improves flow, focus, and delivery speed.
Kanban example
Board:
To Do → In Progress → Review → Done
Suppose In Progress WIP limit = 3.
If there are already 3 items in In Progress, the team cannot pull another item from To Do.
They must first finish something and move it to Review or Done.
Simple class example
“In Kanban, we do not keep starting new work just because work exists. We pull work only when there is available capacity.”
Example with Review
If Review WIP limit = 2 and Review already has 2 items, the developer should not push another completed item into Review. Instead, the team may help clear Review first.
Teaching line
Pull system means: finish work before starting more work. It protects the team from overload and keeps work flowing smoothly.