Skip to content

Commit 087687f

Browse files
committed
Editorial changes - mostly formatting
1 parent 8ebe0df commit 087687f

8 files changed

Lines changed: 292 additions & 232 deletions

File tree

reference/7.6/Microsoft.PowerShell.Core/About/about_Automatic_Variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes variables that store state information for PowerShell. These variables are created and maintained by PowerShell.
33
Locale: en-US
4-
ms.date: 02/10/2026
4+
ms.date: 04/02/2026
55
no-loc: [Reset, Current, Background, Blink, Bold, Foreground, Formatting, Hidden, Italic, Reset, Reverse, Underline, PSEventArgs, PSEventSubscriber, PSEdition]
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.6&WT.mc_id=ps-gethelp
77
schema: 2.0.0

reference/7.6/Microsoft.PowerShell.Core/About/about_CommonParameters.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the parameters that can be used with any cmdlet.
33
Locale: en-US
4-
ms.date: 03/29/2026
4+
ms.date: 04/02/2026
55
no-loc: [Confirm, Debug, ErrorAction, ErrorVariable, InformationAction, InformationVariable, OutBuffer, OutVariable, PipelineVariable, ProgressAction, Verbose, WarningAction, WarningVariable, WhatIf]
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.6&WT.mc_id=ps-gethelp
77
schema: 2.0.0
@@ -106,8 +106,7 @@ the display of debugging messages when `$DebugPreference` isn't
106106

107107
Determines how the cmdlet responds to a non-terminating error from the command.
108108
This parameter overrides the value of the `$ErrorActionPreference` variable for
109-
non-terminating errors generated by the command, such as those from the
110-
`Write-Error` cmdlet.
109+
non-terminating errors generated by the command or the `Write-Error` cmdlet.
111110

112111
```yaml
113112
Type: ActionPreference

reference/7.6/Microsoft.PowerShell.Core/About/about_Error_Handling.md

Lines changed: 213 additions & 146 deletions
Large diffs are not rendered by default.

reference/7.6/Microsoft.PowerShell.Core/About/about_Preference_Variables.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Variables that customize the behavior of PowerShell.
33
Locale: en-US
4-
ms.date: 03/29/2026
4+
ms.date: 04/02/2026
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.6&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Preference_Variables
@@ -399,8 +399,8 @@ The valid values are as follows:
399399
- **SilentlyContinue**: No effect. The error message isn't displayed and
400400
execution continues without interruption.
401401
- **Stop**: Displays the error message and stops executing. In addition to the
402-
error generated, the **Stop** value generates an ActionPreferenceStopException
403-
object to the error stream.
402+
error generated, the **Stop** value generates an
403+
ActionPreferenceStopException object to the error stream.
404404
- **Suspend**: Automatically suspends a workflow job to allow for further
405405
investigation. After investigation, the workflow can be resumed. The
406406
**Suspend** value is intended for per-command use, not for use as saved
@@ -410,11 +410,11 @@ The valid values are as follows:
410410
`$ErrorActionPreference` applies to **both** non-terminating and
411411
statement-terminating errors. Unlike the `-ErrorAction` parameter (which only
412412
affects non-terminating errors), the preference variable can also suppress or
413-
escalate errors generated by `$PSCmdlet.ThrowTerminatingError()`.
414-
When set to **Stop**, it escalates non-terminating errors to
415-
script-terminating errors. For more information about error categories, see
416-
[about_Error_Handling][67]. For more information about the **ErrorAction**
417-
common parameter, see [about_CommonParameters][29].
413+
escalate errors generated by `$PSCmdlet.ThrowTerminatingError()`. When set to
414+
**Stop**, it escalates non-terminating errors to script-terminating errors. For
415+
more information about error categories, see [about_Error_Handling][67]. For
416+
more information about the **ErrorAction** common parameter, see
417+
[about_CommonParameters][29].
418418

419419
Many native commands write to `stderr` as an alternative stream for additional
420420
information. This behavior can cause confusion when looking through errors or

reference/7.6/Microsoft.PowerShell.Core/About/about_Throw.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the `throw` keyword, which generates a script-terminating error by default.
33
Locale: en-US
4-
ms.date: 03/29/2026
4+
ms.date: 04/02/2026
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_throw?view=powershell-7.6&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Throw
@@ -10,28 +10,27 @@ title: about_Throw
1010

1111
## Short description
1212

13-
Describes the `throw` keyword that generates a script-terminating error by
13+
Describes the `throw` keyword, which generates a script-terminating error by
1414
default.
1515

1616
## Long description
1717

1818
The `throw` keyword causes a script-terminating error by default. You can use
1919
the `throw` keyword to stop the processing of a command, function, or script.
2020

21-
Unlike statement-terminating errors (generated by
22-
`$PSCmdlet.ThrowTerminatingError()`), the `throw` keyword unwinds the entire
21+
Unlike statement-terminating errors, the `throw` keyword unwinds the entire
2322
call stack. Execution stops completely unless the error is caught by a
2423
`try/catch` block or `trap` statement.
2524

2625
> [!NOTE]
27-
> `$ErrorActionPreference` can suppress `throw`. When set to
28-
> `SilentlyContinue` or `Ignore`, the error does not propagate and
29-
> execution continues at the next statement. When calling an advanced
30-
> function with `-ErrorAction SilentlyContinue`, the parameter translates
31-
> to a scope-local `$ErrorActionPreference` value, so it also suppresses
32-
> `throw` inside that function. Even when suppressed, `throw` still records
33-
> an entry in `$Error``Ignore` only prevents `$Error` recording for
34-
> non-terminating errors.
26+
> `$ErrorActionPreference` can suppress `throw`. When set to `SilentlyContinue`
27+
> or `Ignore`, the error doesn't propagate and execution continues at the next
28+
> statement. When calling an advanced function with
29+
> `-ErrorAction SilentlyContinue`, the parameter translates to a scope-local
30+
> `$ErrorActionPreference` value, so it also suppresses `throw` inside that
31+
> function. Even when suppressed, `throw` still records an entry in `$Error`.
32+
> The `Ignore` value only prevents `$Error` recording for non-terminating
33+
> errors like those generated by `$PSCmdlet.ThrowTerminatingError()`.
3534
3635
For more information about error categories and `$ErrorActionPreference`
3736
behavior, see [about_Error_Handling](about_Error_Handling.md).

reference/7.6/Microsoft.PowerShell.Core/About/about_Trap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes a keyword that handles statement-terminating and script-terminating errors.
33
Locale: en-US
4-
ms.date: 03/29/2026
4+
ms.date: 04/02/2026
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_trap?view=powershell-7.6&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Trap

reference/7.6/Microsoft.PowerShell.Core/About/about_Try_Catch_Finally.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to use the `try`, `catch`, and `finally` blocks to handle statement-terminating and script-terminating errors.
33
Locale: en-US
4-
ms.date: 03/29/2026
4+
ms.date: 04/02/2026
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_try_catch_finally?view=powershell-7.6&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Try_Catch_Finally
@@ -17,10 +17,12 @@ statement-terminating and script-terminating errors.
1717

1818
Use `try`, `catch`, and `finally` blocks to respond to or handle terminating
1919
errors in scripts. PowerShell has two kinds of terminating errors:
20-
_statement-terminating_ errors that stop the current statement and
21-
_script-terminating_ errors that unwind the entire call stack. Both kinds are
22-
caught by `try/catch`. The `trap` statement can also be used to handle
23-
terminating errors. For more information, see [about_Trap][05]. For a
20+
21+
- _statement-terminating_ errors that stop the current statement and
22+
- _script-terminating_ errors that unwind the entire call stack
23+
24+
Both kinds are caught by `try/catch`. You can also use the `trap` statement to
25+
handle terminating errors. For more information, see [about_Trap][05]. For a
2426
comprehensive overview of all error types, see [about_Error_Handling][06].
2527

2628
A statement-terminating error stops the current statement from running, but
@@ -30,10 +32,10 @@ the `throw` keyword) stops the entire script unless caught by a `try/catch`
3032
block or `trap` statement.
3133

3234
> [!NOTE]
33-
> `$ErrorActionPreference` can suppress `throw`. When set to
34-
> `SilentlyContinue` or `Ignore`, the error does not propagate and
35-
> execution continues at the next statement. For details, see
36-
> [Script-terminating errors][07] in **about_Error_Handling**.
35+
> `$ErrorActionPreference` can suppress `throw`. When set to `SilentlyContinue`
36+
> or `Ignore`, the error doesn't propagate and execution continues at the next
37+
> statement. For details, see the _Script-terminating errors_ section of
38+
> [about_Error_Handling][07].
3739
3840
Use the `try` block to define a section of a script in which you want
3941
PowerShell to monitor for errors. When an error occurs within the `try` block,

reference/docs-conceptual/learn/deep-dives/everything-about-exceptions.md

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Error handling is just part of life when it comes to writing code.
33
ms.custom: contributor-KevinMarquette
4-
ms.date: 03/29/2026
4+
ms.date: 04/02/2026
55
title: Everything you wanted to know about exceptions
66
---
77
# Everything you wanted to know about exceptions
@@ -12,9 +12,9 @@ can easily handle exceptions generated by other people's code or you can generat
1212
exceptions for others to handle.
1313

1414
> [!NOTE]
15-
> The [original version][07] of this article appeared on the blog written by [@KevinMarquette][08].
15+
> The [original version][08] of this article appeared on the blog written by [@KevinMarquette][09].
1616
> The PowerShell team thanks Kevin for sharing this content with us. Please check out his blog at
17-
> [PowerShellExplained.com][05].
17+
> [PowerShellExplained.com][06].
1818
1919
## Basic terminology
2020

@@ -44,16 +44,18 @@ it.
4444

4545
### Terminating and non-terminating errors
4646

47-
PowerShell has three categories of errors. A _non-terminating error_ (generated
48-
by `Write-Error`) adds an error to the error stream without stopping execution
49-
and does not trigger `catch`. A _statement-terminating error_ (generated by
50-
`$PSCmdlet.ThrowTerminatingError()`, engine errors, or .NET method exceptions)
51-
stops the current statement but allows the script to continue at the next
52-
statement. A _script-terminating error_ (generated by `throw`, parse errors, or
53-
`-ErrorAction Stop` escalation) unwinds the entire call stack. Both
54-
statement-terminating and script-terminating errors can be caught by
55-
`try/catch`. For a comprehensive reference, see
56-
[about_Error_Handling](/powershell/module/microsoft.powershell.core/about/about_error_handling).
47+
PowerShell has three categories of errors.
48+
49+
- A _non-terminating error_ adds an error to the error stream without stopping execution and doesn't
50+
trigger `catch`. By default, `Write-Error` generates non-terminating errors.
51+
- A _statement-terminating error_ stops the current statement but allows the script to continue at
52+
the next statement. Statement-terminating errors can be generated by engine errors,
53+
`$PSCmdlet.ThrowTerminatingError()`, or .NET method exceptions.
54+
- A _script-terminating error_ unwinds the entire call stack. Script-terminating errors can be
55+
generated by `throw`, parse errors, or `-ErrorAction Stop` escalation.
56+
57+
Both statement-terminating and script-terminating errors can be caught by `try/catch`. For a
58+
comprehensive reference, see [about_Error_Handling][04].
5759

5860
### Swallowing an exception
5961

@@ -111,7 +113,7 @@ Start-Something -ErrorAction Stop
111113
```
112114

113115
For more information about the **ErrorAction** parameter, see [about_CommonParameters][03]. For more
114-
information about the `$ErrorActionPreference` variable, see [about_Preference_Variables][04].
116+
information about the `$ErrorActionPreference` variable, see [about_Preference_Variables][05].
115117

116118
### Try/Catch
117119

@@ -430,7 +432,7 @@ catch [System.IO.FileNotFoundException]
430432
I compiled a master list with the help of the Reddit `r/PowerShell` community that contains hundreds
431433
of .NET exceptions to complement this post.
432434

433-
- [The big list of .NET exceptions][06]
435+
- [The big list of .NET exceptions][07]
434436

435437
I start by searching that list for exceptions that feel like they would be a good fit for my
436438
situation. You should try to use exceptions in the base `System` namespace.
@@ -562,57 +564,50 @@ the users of your Cmdlet.
562564

563565
## How try/catch changes error propagation
564566

565-
Inside a `try` block, PowerShell sets an internal flag that causes all
566-
statement-terminating errors to propagate to the `catch` block. This is by
567-
design, not a corner case. The following example demonstrates this behavior.
568-
569-
Outside `try/catch`, a statement-terminating error from a child scope does not
570-
stop the parent scope. Here is a function that generates a divide by zero
571-
runtime exception.
567+
Inside a `try` block, PowerShell sets an internal flag that causes all statement-terminating errors
568+
to propagate to the `catch` block. This is by design, not a corner case. The following example
569+
demonstrates this behavior.
572570

573571
```powershell
574572
function Start-Something { 1/(1-1) }
575573
```
576574

575+
Outside `try/catch`, a statement-terminating error from a child scope doesn't stop the parent scope.
576+
Here is a function that generates a divide by zero runtime exception.
577+
577578
Invoke it like this to see the error reported while the script continues.
578579

579580
```powershell
580581
&{ Start-Something; Write-Output "We did it. Send Email" }
581582
```
582583

583-
But placing that same code inside a `try/catch`, the error propagates to the
584-
`catch` block.
584+
But placing that same code inside a `try/catch`, the error propagates to the `catch` block.
585585

586586
```powershell
587-
try
588-
{
587+
try {
589588
&{ Start-Something; Write-Output "We did it. Send Email" }
590-
}
591-
catch
592-
{
589+
} catch {
593590
Write-Output "Notify Admin to fix error and send email"
594591
}
595592
```
596593

597-
The error is caught and the subsequent `Write-Output` inside the script block
598-
does not run. This is standard `try/catch` behavior — all terminating errors
599-
within the `try` block are caught, whether they originate in the current scope
600-
or in a child scope.
594+
The error is caught and the subsequent `Write-Output` inside the script block doesn't run. This is
595+
standard `try/catch` behavior — all terminating errors within the `try` block are caught, whether
596+
they originate in the current scope or in a child scope.
601597

602598
### $PSCmdlet.ThrowTerminatingError() inside try/catch
603599

604-
`$PSCmdlet.ThrowTerminatingError()` creates a statement-terminating error
605-
within the cmdlet. After the error leaves the cmdlet, the caller treats it as a
606-
non-terminating error by default. The caller can escalate it back to a
607-
terminating error by using `-ErrorAction Stop` or calling it from within a
608-
`try{...}catch{...}`.
600+
`$PSCmdlet.ThrowTerminatingError()` creates a statement-terminating error within the cmdlet. After
601+
the error leaves the cmdlet, the caller treats it as a non-terminating error by default. The caller
602+
can escalate it back to a terminating error by using `-ErrorAction Stop` or calling it from within a
603+
`try/catch` block.
609604

610605
### Public function templates
611606

612-
One last takeaway I had with my conversation with Kirk Munro was that he places a
613-
`try{...}catch{...}` around every `begin`, `process` and `end` block in all of his advanced
614-
functions. In those generic catch blocks, he has a single line using
615-
`$PSCmdlet.ThrowTerminatingError($PSItem)` to deal with all exceptions leaving his functions.
607+
One last takeaway I had with my conversation with Kirk Munro was that he places a `try/catch` block
608+
inside every `begin`, `process` and `end` block in all his advanced functions. In those generic
609+
catch blocks, he has a single line using `$PSCmdlet.ThrowTerminatingError($PSItem)` to deal with all
610+
exceptions leaving his functions.
616611

617612
```powershell
618613
function Start-Something
@@ -622,12 +617,9 @@ function Start-Something
622617
623618
process
624619
{
625-
try
626-
{
620+
try {
627621
...
628-
}
629-
catch
630-
{
622+
} catch {
631623
$PSCmdlet.ThrowTerminatingError($PSItem)
632624
}
633625
}
@@ -677,8 +669,9 @@ advice and make `ThrowTerminatingError` my goto exception handler for every func
677669
[01]: /dotnet/api
678670
[02]: /dotnet/api/System.IO.FileNotFoundException
679671
[03]: /powershell/module/microsoft.powershell.core/about/about_commonparameters
680-
[04]: /powershell/module/microsoft.powershell.core/about/about_preference_variables
681-
[05]: https://powershellexplained.com/
682-
[06]: https://powershellexplained.com/2017-04-07-all-dotnet-exception-list
683-
[07]: https://powershellexplained.com/2017-04-10-Powershell-exceptions-everything-you-ever-wanted-to-know/
684-
[08]: https://twitter.com/KevinMarquette
672+
[04]: /powershell/module/microsoft.powershell.core/about/about_error_handling
673+
[05]: /powershell/module/microsoft.powershell.core/about/about_preference_variables
674+
[06]: https://powershellexplained.com/
675+
[07]: https://powershellexplained.com/2017-04-07-all-dotnet-exception-list
676+
[08]: https://powershellexplained.com/2017-04-10-Powershell-exceptions-everything-you-ever-wanted-to-know/
677+
[09]: https://twitter.com/KevinMarquette

0 commit comments

Comments
 (0)