Cmdlet.ThrowTerminatingError
Method
Definition
Terminate the command and report an error
public void ThrowTerminatingError (System.Management.Automation.ErrorRecord errorRecord);
Parameters
- errorRecord
- ErrorRecord
The error which caused the command to be terminated
Exceptions
always
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 href="System.Management.Automation.Cmdlet.ProcessRecord"></xref>,
<xref href="System.Management.Automation.Cmdlet.BeginProcessing"></xref> or
<xref href="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 href="System.Management.Automation.Cmdlet.ThrowTerminatingError(System.Management.Automation.ErrorRecord)"></xref>,
so that the additional information in
<xref href="System.Management.Automation.ErrorRecord"></xref>
is available.
<xref href="System.Management.Automation.Cmdlet.ThrowTerminatingError(System.Management.Automation.ErrorRecord)"></xref>
always throws
<xref href="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 href="System.Management.Automation.PipelineStoppedException"></xref>.
to percolate up to the caller of
<xref href="System.Management.Automation.Cmdlet.ProcessRecord"></xref>.
etc.