Cmdlet.ThrowTerminatingError(ErrorRecord) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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 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.