This topic discusses the method used to report non-terminating errors. It also discusses how to call the method from within the cmdlet.
When a non-terminating error occurs, the cmdlet should report this error by calling the WriteError method. When the cmdlet reports a non-terminating error, the cmdlet can continue to operate on this input object and on further incoming pipeline objects. If the cmdlet calls the WriteError method, the cmdlet can write an error record that describes the condition that caused the non-terminating error. For more information about error records, see Windows PowerShell Error Records.
Cmdlets can call WriteError as necessary from within their input processing methods. However, cmdlets can call WriteError only from the thread that called the BeginProcessing, ProcessRecord, or EndProcessing input processing method. Do not call WriteError from another thread. Instead, communicate errors back to the main thread.