IContainsErrorRecord Interface

Definition

Implemented by exception classes which contain additional ErrorRecord information.

public interface IContainsErrorRecord
Derived

Remarks

MSH defines certain exception classes which implement this interface. This includes wrapper exceptions such as CmdletInvocationException, and also MSH 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
        <xref href="System.Management.Automation.IContainsErrorRecord"></xref>,
        but it is generally preferable for Cmdlets and CmdletProviders to communicate
        <xref href="System.Management.Automation.IContainsErrorRecord.ErrorRecord"></xref>
        information using
        <xref href="System.Management.Automation.Cmdlet.ThrowTerminatingError(System.Management.Automation.ErrorRecord)"></xref>
        or
        <xref href="System.Management.Automation.Provider.CmdletProvider.ThrowTerminatingError(System.Management.Automation.ErrorRecord)"></xref>
        rather than by throwing an exception which implements
        <xref href="System.Management.Automation.IContainsErrorRecord"></xref>.
        Consider implementing
        <seealso cref="T:System.Management.Automation.IContainsErrorRecord"></seealso>
        in your custom exception only if you throw it from a context
        where a reference to the active
        <seealso cref="T:System.Management.Automation.Cmdlet"></seealso> or
        <seealso cref="T:System.Management.Automation.Provider.CmdletProvider"></seealso>
        is no longer available.

Properties

ErrorRecord

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