1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
<html dir="ltr"><head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="assetid" CONTENT="HV01039912"><META NAME="lcid" CONTENT="1033"><title>Handling errors</title><link rel="stylesheet" type="text/css" href="office10.css"><script type="text/javascript" language="Javascript" src="ExpCollapse.js"></script><script type="text/javascript" language="JavaScript" src="inline.js"></script></head><body><p id="ExpandAllLine" class="ExpFav"><a href="#" onclick="ExpandAll()" onkeypress="ExpandAll()" class="DropDown"><img id="picHeader" border="0" src="expandtri.gif" alt="Show All"><span id="ExpandAll">Show All</span></a></p><h1>Handling errors</h1><div class="ofvbanav"><span class="ofvbanavreuse" id="seealso" onclick="toggleList()" onkeypress="toggleList()"></span><span class="ofvbanavreuse" id="specifics" onclick="toggleList()" onkeypress="toggleList()"></span></div><p>When creating custom applications, developers must often perform error handling that involves writing programming code to check for errors raised by the application or to create and raise custom errors. The Microsoft Office InfoPath 2003 object model supports error handling through the use of the <b class="bterm"><a href="xdobjError.htm" id="HV01021243" lcid=" ">Error</a></b> object in association with the <b class="bterm"><a href="xdcolErrors.htm" id="HV01021186" lcid=" ">Errors</a></b> collection.</p><p>In InfoPath, errors can occur when a form's <a href="#" class="glossary" onclick="AppendPopup(this,'OfXmlSchemas')" onkeypress="AppendPopup(this,'OfXmlSchemas')">XML Schema</a> is validated, when a custom validation constraint fails, when an error is generated by the <b class="bterm"><a href="xdmthReportError.htm" id="HV01021405" lcid=" ">ReportError</a></b> method of the <b class="bterm"><a href="xdobjDataDOMEvent.htm" id="HV01021239" lcid=" ">DataDOMEvent</a></b> object, or when an error is created using the <b class="bterm"><a href="xdmthAdd.htm" id="HV01021375" lcid=" ">Add</a></b> method of the <b class="bterm">Errors</b> collection.</p><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Overview of the Errors collection</a></p><div id="ExpCol" class="collapsed" border="0"><p>The <b class="bterm">Errors</b> collection provides the following methods and properties that form developers can use to manage the <b class="bterm">Error</b> objects that the collection contains.</p><table><tr><th>Name</th><th>Description</th></tr><tr><td><b class="bterm"><a href="xdmthAdd.htm" id="HV01021375" lcid=" ">Add</a></b> method</td><td>Creates an <b class="bterm">Error</b> object and adds it to the collection</td></tr><tr><td><b class="bterm"><a href="xdmthDelete.htm" id="HV01021382" lcid=" ">Delete</a></b> method</td><td>Deletes all <b class="bterm">Error</b> objects associated with the specified XML node and condition name</td></tr><tr><td><b class="bterm"><a href="xdmthDeleteAll.htm" id="HV01021383" lcid=" ">DeleteAll</a></b> method</td><td>Deletes all <b class="bterm">Error</b> objects contained in the collection</td></tr><tr><td><b class="bterm"><a href="xdproCount_3.htm" id="HV01021273" lcid=" ">Count</a></b> property</td><td>Returns a count of the number of <b class="bterm">Error</b> objects contained in the collection</td></tr><tr><td><b class="bterm"><a href="xdproItem_3.htm" id="HV01021296" lcid=" ">Item</a></b> property</td><td>Returns a reference to an <b class="bterm">Error</b> object based on the specified index number</td></tr></table></div><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Overview of the Error object</a></p><div id="ExpCol" class="collapsed" border="0"><p>The <b class="bterm">Error</b> object provides the following properties that form developers can use to access information about the error object.</p><table><tr><th>Name</th><th>Description</th></tr><tr><td><b class="bterm"><a href="xdproConditionName.htm" id="HV01024628" lcid=" ">ConditionName</a></b> property</td><td>Returns the name of the error condition, or returns null, depending on the type of <b class="bterm">Error</b> object</td></tr><tr><td><b class="bterm"><a href="xdproDetailedErrorMessage.htm" id="HV01021280" lcid=" ">DetailedErrorMessage</a></b> property</td><td>Specifies or retrieves the detailed error message of the <b class="bterm">Error</b> object</td></tr><tr><td><b class="bterm"><a href="xdproErrorCode.htm" id="HV01021282" lcid=" ">ErrorCode</a></b> property</td><td>Specifies or retrieves the error code of the <b class="bterm">Error</b> object</td></tr><tr><td><b class="bterm"><a href="xdproNode.htm" id="HV01021313" lcid=" ">Node</a></b> property</td><td>Returns a reference to the XML node associated with the <b class="bterm">Error</b> object</td></tr><tr><td><b class="bterm"><a href="xdproShortErrorMessage.htm" id="HV01021331" lcid=" ">ShortErrorMessage</a></b> property</td><td>Specifies or retrieves the short error message of the <b class="bterm">Error</b> object</td></tr><tr><td><b class="bterm"><a href="xdproType_3.htm" id="HV01021346" lcid=" ">Type</a></b> property</td><td>Returns the type of the <b class="bterm">Error</b> object</td></tr></table></div><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Using the Errors collection and the Error object</a></p><div id="ExpCol" class="collapsed" border="0"><p>The <b class="bterm">Errors</b> collection is accessed through the <b class="bterm"><a href="xdproErrors.htm" id="HV01021283" lcid=" ">Errors</a></b> property of the <b class="bterm"><a href="xdobjXDocument.htm" id="HV01021254" lcid=" ">XDocument</a></b> object. The <b class="bterm">Errors</b> collection is associated with a form's underlying XML document so that when an error occurs, it occurs within the XML document. The following example demonstrates how a Microsoft <a href="#" class="glossary" onclick="AppendPopup(this,'ofjscript')" onkeypress="AppendPopup(this,'ofjscript')">JScript</a> <b class="bterm"> for</b> loop can be used to check the errors that may exist in a form's underlying XML document. The function first checks the <b class="bterm">Count</b> property of the <b class="bterm">Errors</b> collection to determine whether any errors are present. If there are errors, the function loops through each of them, and, using the <b class="bterm">ShortErrorMessage</b> property of the <b class="bterm">Error</b> object, displays a message box to the user.</p><pre><code>function CheckErrors(xmlNode)
{
for (var i=0; i<XDocument.Errors.Count; i++)
{
var objError = XDocument.Errors(i);
if (xmlNode == objError.Node)
{
XDocument.UI.Alert("The following error has occured: " +
objError.ShortErrorMessage + ".");
}
}
}</code></pre><p>The preceding function could be called from one of the form's data validation <a href="#" class="glossary" onclick="AppendPopup(this,'xdeventhandler')" onkeypress="AppendPopup(this,'xdeventhandler')">event handlers</a>. For example, when used in the <b class="bterm"><a href="xdevtOnAfterChange.htm" id="HV01021366" lcid=" ">OnAfterChange</a></b> event for a field in the form, the call to the function would pass the XML node argument using the <b class="bterm"><a href="xdproSite.htm" id="HV01021332" lcid=" ">Site</a></b> property of the <b class="bterm">DataDOMEvent</b> object as follows:</p><pre><code>CheckErrors(eventObj.Site);</code></pre><p>In addition to handling errors generated by InfoPath, form developers can also generate their own custom errors by using the <b class="bterm">ReportError</b> method of the <b class="bterm">DataDOMEvent</b> object, or by using the <b class="bterm">Add</b> method of the <b class="bterm">Errors</b> collection. For information about using the <b class="bterm">ReportError</b> or <b class="bterm">Add</b> methods, click the methods at the beginning of this topic.</p></div><script type="text/javascript" language="JScript" src="ofvbanl.js"></script><span id="ofVBAISpan" class="ofvbaispan"><iframe id="ofVBAIFrame" frameborder="0" marginheight="0" marginwidth="4" scrolling="auto" width="100%" src="../links/inconHandlingErrors_l.htm"></iframe></span><center><a href="XMLSchemaCopyright_HV01147162.htm">©2003-2004 Microsoft Corporation. All rights reserved.</a>
Permission to copy, display and distribute this document is available at: <a
href="http://r.office.microsoft.com/r/rlidAWSContentRedir?AssetID=XT010988631033&CTT=11&Origin=HV011232471033"
target="_new">http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp</a></center></body></html>
|