Compartilhar via


ICommandRuntime.ThrowTerminatingError(ErrorRecord) Method

Definition

This interface will be called to route fatal errors from a cmdlet.

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);
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
[System.Runtime.CompilerServices.NullableContext(1)]
public void ThrowTerminatingError (System.Management.Automation.ErrorRecord errorRecord);
abstract member ThrowTerminatingError : System.Management.Automation.ErrorRecord -> unit
[<System.Diagnostics.CodeAnalysis.DoesNotReturn>]
abstract member ThrowTerminatingError : System.Management.Automation.ErrorRecord -> unit
[<System.Diagnostics.CodeAnalysis.DoesNotReturn>]
[<System.Runtime.CompilerServices.NullableContext(1)>]
abstract member 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

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.

It is up to the implementation of this routine to determine what if any information is to be added. It should encapsulate the error record into an exception and then throw that exception.

Applies to