Cmdlet.ThrowTerminatingError(ErrorRecord) Cmdlet.ThrowTerminatingError(ErrorRecord) 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);
member this.ThrowTerminatingError : System.Management.Automation.ErrorRecord -> unit
Parameters
errorRecord
ErrorRecord ErrorRecord ErrorRecord

The error which caused the command to be terminated

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
     <xref data-throw-if-not-resolved="true" uid="System.Management.Automation.Cmdlet.ProcessRecord"></xref>,
     <xref data-throw-if-not-resolved="true" uid="System.Management.Automation.Cmdlet.BeginProcessing"></xref> or
     <xref data-throw-if-not-resolved="true" uid="System.Management.Automation.Cmdlet.EndProcessing"></xref>
     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
     <xref data-throw-if-not-resolved="true" uid="System.Management.Automation.Cmdlet.ThrowTerminatingError(System.Management.Automation.ErrorRecord)"></xref>,
     so that the additional information in
     <xref data-throw-if-not-resolved="true" uid="System.Management.Automation.ErrorRecord"></xref>
     is available.

     <xref data-throw-if-not-resolved="true" uid="System.Management.Automation.Cmdlet.ThrowTerminatingError(System.Management.Automation.ErrorRecord)"></xref>
     always throws
     <xref data-throw-if-not-resolved="true" uid="System.Management.Automation.PipelineStoppedException"></xref>,
     regardless of what error was specified in <code data-dev-comment-type="paramref">errorRecord</code>.
     The Cmdlet should generally just allow
     <xref data-throw-if-not-resolved="true" uid="System.Management.Automation.PipelineStoppedException"></xref>.
     to percolate up to the caller of
     <xref data-throw-if-not-resolved="true" uid="System.Management.Automation.Cmdlet.ProcessRecord"></xref>.
     etc.

Applies to