Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Cmdlet.ThrowTerminatingError Method (ErrorRecord)

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Reports a terminating error when the cmdlet cannot continue, or when you do not want the cmdlet to continue to process records.

Namespace:   System.Management.Automation
Assembly:  System.Management.Automation (in System.Management.Automation.dll)

Public Sub ThrowTerminatingError (
	errorRecord As ErrorRecord
)

Parameters

errorRecord
Type: System.Management.Automation.ErrorRecord

An ErrorRecord object that describes the error condition.

When a cmdlet encounters a terminating error, call this method rather than simply throwing an exception. Calling this method allows the cmdlet to attach additional error record information that describes the condition that caused the terminating error. When this method is called, the Windows PowerShell runtime catches the error record and then starts shutting down the pipeline. For more information about error reporting and error records, see Windows PowerShell Error Reporting.

This method should not be used when errors occur where the cmdlet can continue processing records. To send error reports when nonterminating errors occur, call the WriteError method.

For more information about cmdlets, see Windows PowerShell Cmdlets.

The following code example uses ThrowTerminatingError to throw a terminating error.

protected override void ProcessRecord()
{
  try
  {
    // If an IUpdateServer was not passed to this cmdlet as a parameter, then connect to the local WSUS server
    if (updateServer == null)
    {
      updateServer = AdminProxy.GetUpdateServer();
    }
    WriteVerbose(WUCmdlets.Resources.ConnectedToServer + updateServer.Name);

    // Call appropriate method depending on which parameter set is being used.
    if (this.updateServer != null)
    {
      if (this.All == true)
      {
        GetComputersAll();
      }
      else if (this.ComputerName != null)
      {
        GetComputersByName();
      }
      else 
      {
        GetComputersScoped();
      }
    }
    else
    {
      WUCommon.ThrowTerminatingError(WUCommon.ErrorType.NullServer, this, null);
    }
  }
  catch (WsusInvalidServerException ex)
  {
    WUCommon.ThrowTerminatingError(WUCommon.ErrorType.InvalidServer, this, ex);
  }
  catch (WsusObjectNotFoundException ex)
  {
    WUCommon.ThrowTerminatingError(WUCommon.ErrorType.ObjectNotFound, this, ex);
  }
  catch (Exception ex)
  {
    WUCommon.ThrowTerminatingError(WUCommon.ErrorType.UnexpectedError, this, ex);
  }
}//End ProcessRecord()
Return to top

Community Additions

Show: