通过


非终止错误

本主题讨论用于报告非终止错误的方法。 它还讨论如何从 cmdlet 中调用 方法。

发生非终止错误时,cmdlet 应调用 System.Management.Automation.Cmdlet.WriteError 方法报告此错误。 当 cmdlet 报告非终止错误时,cmdlet 可以继续对此输入对象和进一步的传入管道对象进行操作。 如果 cmdlet 调用 System.Management.Automation.Cmdlet.WriteError 方法,则 cmdlet 可以编写错误记录,描述导致非终止错误的条件。 有关错误记录的详细信息,请参阅Windows PowerShell记录

Cmdlet 可在必要时从输入处理方法中调用System.Management.Automation.Cmdlet.WriteError。 但是,cmdlet 只能从调用 System.Management.Automation.Cmdlet.BeginProcessing、System.Management.Automation.Cmdlet.ProcessRecord 或System.Management.Automation.Cmdlet.EndProcessing 输入处理方法的线程调用 System.Management.Automation.Cmdlet.WriteError。 不要从另一个线程调用System.Management.Automation.Cmdlet.WriteError。 相反,将错误传递回主线程。

另请参阅

System.Management.Automation.Cmdlet.WriteError

System.Management.Automation.Cmdlet.BeginProcessing

System.Management.Automation.Cmdlet.ProcessRecord

System.Management.Automation.Cmdlet.EndProcessing

Windows PowerShell 错误记录

编写 Windows PowerShell Cmdlet