# Errors Collection

Errors Error

Contains an Error object for each error within a Microsoft Office InfoPath 2003 form. An Error object contains information about an InfoPath error, including its detailed message, short message, code, type, and the XML node that is associated with it.

## Remarks

The Errors collection is a full-featured collection— it provides properties and methods for adding, deleting, and gaining access to the Error objects that it contains.

In addition to managing the errors generated by InfoPath, the Errors collection can also be used to create custom errors using the Add method.

Note Custom errors can also be created using the ReportError method of the DataDOMEvent object.

## Using the Errors collection

The Errors collection is accessed through the Errors property of the XDocument object. The Errors collection is associated with a form's underlying XML document so that when an error occurs, it occurs within the XML document.

In the following example, the Count property of the Errors collection is used get the count of errors currently contained in the collection:

    XDocument.UI.Alert("Count of errors: " + XDocument.Errors.Count);

To delete a specific error from the Errors collection, use the Delete method, passing the XML code and condition name as arguments:

    XDocument.Errors.Delete(myXMLNode, "MyErrorName");

To delete all of the errors in the Errors collection, use the DeleteAll method:

    XDocument.Errors.DeleteAll();

To set a reference to an error within the Errors collection, use the Item property:

    var objError;

    objError = XDocument.Errors.Item(0);
    // Or...
    objError = XDocument.Errors(0);

For more information about using the Errors collection, see Handling errors.

©2003-2004 Microsoft Corporation. All rights reserved. Permission to copy, display and distribute this document is available at: http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp