Cmdlet.ThrowTerminatingError(ErrorRecord) Cmdlet.ThrowTerminatingError(ErrorRecord) Cmdlet.ThrowTerminatingError(ErrorRecord) Method


Terminate the command and report an error

 void ThrowTerminatingError(System::Management::Automation::ErrorRecord ^ errorRecord);
public void ThrowTerminatingError (System.Management.Automation.ErrorRecord errorRecord);
member this.ThrowTerminatingError : System.Management.Automation.ErrorRecord -> unit


ErrorRecord ErrorRecord ErrorRecord

The error which caused the command to be terminated



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