IContainsErrorRecord Interface

Definition

Implemented by exception classes which contain additional ErrorRecord information.

public interface class IContainsErrorRecord
public interface IContainsErrorRecord
[System.Runtime.CompilerServices.NullableContext(1)]
public interface IContainsErrorRecord
type IContainsErrorRecord = interface
[<System.Runtime.CompilerServices.NullableContext(1)>]
type IContainsErrorRecord = interface
Public Interface IContainsErrorRecord
Derived
Attributes

Remarks

PowerShell defines certain exception classes which implement this interface. This includes wrapper exceptions such as CmdletInvocationException, and also PowerShell engine errors such as GetValueException. Cmdlets and providers should not define this interface; instead, they should use the WriteError(ErrorRecord) or ThrowTerminatingError(ErrorRecord) methods. The ErrorRecord property will contain an ErrorRecord which contains an instance of ParentContainsErrorRecordException rather than the actual exception.

Do not call WriteError(e.ErrorRecord). The ErrorRecord contained in the ErrorRecord property of an exception which implements IContainsErrorRecord should not be passed directly to WriteError, since it contains a ParentContainsErrorRecordException rather than the real exception.

It is permitted for PSSnapins to implement custom Exception classes which implement IContainsErrorRecord, but it is generally preferable for Cmdlets and CmdletProviders to communicate ErrorRecord information using ThrowTerminatingError(ErrorRecord) or ThrowTerminatingError(ErrorRecord) rather than by throwing an exception which implements IContainsErrorRecord. Consider implementing in your custom exception only if you throw it from a context where a reference to the active or is no longer available.

Properties

ErrorRecord

This is the ErrorRecord which provides additional information about the error.

Applies to