Find the failing operation before changing the script
The red text is an observation. Identify the operation, the error behavior and the smallest check that separates plausible causes. This guide gives you three recorded failures to diagnose before a final case.
Diagnostic scenario · recorded fictional outcomes · Microsoft documentation
The task
A catch block handles terminating errors from its try block. Many cmdlets emit non-terminating errors by default; -ErrorAction Stop can promote those cmdlet errors so catch handles them. Adding try/catch does not make every error terminating, and formatting cannot repair a failed operation.
- Tell a non-terminating cmdlet error from a catchable failure.
- Separate command discovery from runtime error handling.
- Check returned properties before blaming formatting.
Genie tip: Tell a non-terminating cmdlet error from a catchable failure.
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Get-Content -LiteralPath 'C:\Reports\missing.csv' -ErrorAction Stop- Stage 1Get-Content
-LiteralPath -ErrorAction
Build the reasoning
Pin down the failing call
Test one read and its failure path. Put that call inside try when catch is supposed to handle it.
Capture the record
Inside catch, $_ is the error record. Preserve diagnostic fields instead of replacing them with a generic success message.
Check the assumption
If a command is absent, investigate the available module and command name before changing its runtime parameters.
Predict → Check → Explain
Choose a case, predict the next useful check and run that diagnostic choice. Outputs below are fictional recordings, not network results.
Recorded outcome
0 of 3 cases solved
Find the mistake
Catching without failing the run
A catch that only writes a friendly string may leave downstream work unable to distinguish failure from a usable result.
Treating suppressed output as success
Suppressing a displayed error does not make the file exist or the read succeed.
For each case, name the evidence that rules out the other choices. A successful earlier check narrows the next question; it does not prove the whole operation works.
Prove it: write it alone
Solve all three recorded cases before this final decision opens.
Prove it: choose the repair that reaches catch
Get-Content -LiteralPath 'C:\Reports\missing.csv'
try { 'Report finished' }
catch { 'Read failed' }
The failing read happens before try.Take it to a real environment
In your own test environment, trigger a known failure and inspect the error record. Avoid broad preference changes as a first repair; a per-command ErrorAction makes the intended failure boundary visible. The decision lab shows recorded outcomes and does not execute try/catch in your browser.