Share via


Cmdlet.ThrowTerminatingError(ErrorRecord) Method

Definition

Terminate the command and report an error.

public:
 void ThrowTerminatingError(System::Management::Automation::ErrorRecord ^ errorRecord);
public void ThrowTerminatingError (System.Management.Automation.ErrorRecord errorRecord);
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
public void ThrowTerminatingError (System.Management.Automation.ErrorRecord errorRecord);
member this.ThrowTerminatingError : System.Management.Automation.ErrorRecord -> unit
[<System.Diagnostics.CodeAnalysis.DoesNotReturn>]
member this.ThrowTerminatingError : System.Management.Automation.ErrorRecord -> unit
Public Sub ThrowTerminatingError (errorRecord As ErrorRecord)

Parameters

errorRecord
ErrorRecord

The error which caused the command to be terminated

Attributes

Exceptions

Remarks

ThrowTerminatingError(ErrorRecord) terminates the command, where WriteError(ErrorRecord) allows the command to continue.

The cmdlet can also terminate the command by simply throwing any exception. When the cmdlet's implementation of ProcessRecord(), BeginProcessing() or EndProcessing() throws an exception, the Engine will always catch the exception and report it as a terminating error. However, it is preferred for the cmdlet to call ThrowTerminatingError(ErrorRecord), so that the additional information in ErrorRecord is available. ThrowTerminatingError(ErrorRecord) always throws PipelineStoppedException, regardless of what error was specified in errorRecord. The Cmdlet should generally just allow PipelineStoppedException. to percolate up to the caller of ProcessRecord(). etc.

Applies to