Error types
As mentioned above, PowerShell defines two different types of errors: terminating and non-terminating errors.
Each command in PowerShell may choose to raise either of these, depending on the operation.
Non-terminating errors
A non-terminating error, a type of informational output, is written without stopping a script. Non-terminating errors exist to allow a command to continue in the event of a partial failure. For example, if a command is acting on a pipeline and one item fails, the command can write an error and continue to process the remaining items.
Non-terminating errors can be written using the Write-Error
command, although a deeper analysis of this approach and alternatives are explored later in this chapter.
The following example demonstrates how a non-terminating error can be used in a function accepting pipeline input:
function Update-Value {
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline)]
...