XPathError class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
<!-- XPathError class -->
<!-- XPathError class -->
 
__NOTOC__
An <var>XPathError</var> exception can be thrown by various methods in the <var>[[XmlDoc API]]</var>.  It indicates an error either in the syntax of an [[XPath]] argument to the method, or in the results returned by that XPath expression.  The various read-only properties of an <var>XPathError</var> object (which can be set by the <var>[[Catch]]</var> statement) provide information about the failed operation.
An <var>XPathError</var> exception can be thrown by various methods in the <var>[[XmlDoc API]]</var>.  It indicates an error either in the syntax of an [[XPath]] argument to the method, or in the results returned by that XPath expression.  The various read-only properties of an <var>XPathError</var> object (which can be set by the <var>[[Catch]]</var> statement) provide information about the failed operation.


Line 36: Line 36:


<h2>CharacterPosition property</h2>
<h2>CharacterPosition property</h2>
{{Template:XPathError:CharacterPosition subtitle}}
<h4>Syntax</h4>
{{Template:XPathError:CharacterPosition syntax}}
<h4>Syntax terms</h4>
<table class="syntaxTable">
<tr><th>%num</th>
<td>The position of the character at which the exception was thrown.
</td></tr>
<tr><th>%XPathErr</th>
<td>An <var>XPathError</var> object.
</td></tr></table>
<h2>Description property</h2>
{{Template:XPathError:Description subtitle}}
<h4>Syntax</h4>
{{Template:XPathError:Description syntax}}
<h4>Syntax terms</h4>
<table class="syntaxTable">
<tr><th>%str</th>
<td>A string to receive the description of the exception.
</td></tr>
<tr><th>%XPathErr</th>
<td>An <var>XPathError</var> object.
</td></tr></table>
<h2>New constructor</h2>
{{Template:XPathError:New subtitle}}
Each argument to <var>New</var> sets the value of the corresponding property of the newly constructed <var>XPathError</var> object.
<h4>Syntax</h4>
{{Template:XPathError:New syntax}}
<h4>Syntax terms</h4>
<table class="syntaxTable">
<tr><th>%XPathErr</th>
<td>An <var>XPathError</var> object.
</td></tr>
<tr><th><b>Reason=</b>reasonEnum</th>
<td>This name required parameter specifies the value to be assigned to the exception object's <var>[[Reason (XPathError property)|Reason]]</var> property.
The Reason parameter is '''not''' optional.
</td></tr>
<tr><th><b>CharacterPosition=</b>num</th>
<td>This name required parameter specifies the numeric value (''num'') to be assigned to the object's <var>[[CharacterPosition (XPathError property)|CharacterPosition]]</var> property.
</td></tr>
<tr><th><b>Description=</b>string</th>
<td>This name required parameter specifies the string value (''string'') to be assigned to the object's <var>[[Description (XPathError property)|Description]]</var> property.
</td></tr></table>
<h2>Reason property</h2>
{{Template:XPathError:Reason subtitle}}
<h4>Syntax</h4>
{{Template:XPathError:Reason syntax}}
<h4>Syntax terms</h4>
<table class="syntaxTable">
<tr><th>%reason</th>
<td>This <var>XPathErrorReason</var> enumeration value describes the reason for the translation failure.
</td></tr>
<tr><th>%XPathErr</th>
<td>An <var>XPathError</var> object.
</td></tr></table>
<h4>Usage notes</h4>
<ul>
<li>An <var>XPathErrorReason</var> enumeration may have one of the following values:
<dl>
<dt>SyntaxError
<dd>A violation of the syntax of an XPath expression.
<dt>EmptyResult
<dd>There are no nodes matched by the XPath expression, and the method
requires at least one matching node.
</dl>
<li>As with all enumerations, you use
the <code>ToString</code> method to convert an enumeration value to a
character string whose value is the name of the enumeration value.
</ul>


[[Category:System exception classes]]
[[Category:System exception classes]]

Revision as of 16:20, 11 May 2011


An XPathError exception can be thrown by various methods in the XmlDoc API. It indicates an error either in the syntax of an XPath argument to the method, or in the results returned by that XPath expression. The various read-only properties of an XPathError object (which can be set by the Catch statement) provide information about the failed operation.

An example of using the XPathError exception is:

%err Object XPathError Try %d:Print('a b c') Catch XPathError To %err PrintText {~} = {%err:Reason} PrintText {~} = {%err:Description} PrintText {~} = {%err:CharacterPosition} End Try

Since the expression in the above invocation of the Print method (a b c) is not a valid XPath expression, the above fragment will result in the following:

%err:Reason = SyntaxError %err:Description = Expect "/" for new step or "[" for predicate %err:CharacterPosition = 3

This class is new in version 7.8 of the Sirius Mods.


The XPathError methods

The following are the available XPathError class methods.

MethodDescription
CharacterPositionPosition of character at of before which the error occurred
DescriptionBrief description of the exception
NewCreate a new XPathError object
ReasonEnumerated cause of the exception

The methods in the class are described in the subsections that follow. In addition:


CharacterPosition property

Position of character at of before which the error occurred (XPathError class)

[Introduced in Sirius Mods 7.8]

Syntax

%number = xPathError:CharacterPosition

Syntax terms

%num The position of the character at which the exception was thrown.
%XPathErr An XPathError object.


Description property

Brief description of the exception (XPathError class)

[Introduced in Sirius Mods 7.8]

Syntax

%string = xPathError:Description

Syntax terms

%str A string to receive the description of the exception.
%XPathErr An XPathError object.


New constructor

Create a new XPathError object (XPathError class)

[Introduced in Sirius Mods 7.8]

Each argument to New sets the value of the corresponding property of the newly constructed XPathError object.

Syntax

%xPathError = [%(XPathError):]New( Reason= xPathErrorReason, - [Description= string], - [CharacterPosition= number])

Syntax terms

%XPathErr An XPathError object.
Reason=reasonEnum This name required parameter specifies the value to be assigned to the exception object's Reason property.

The Reason parameter is not optional.

CharacterPosition=num This name required parameter specifies the numeric value (num) to be assigned to the object's CharacterPosition property.
Description=string This name required parameter specifies the string value (string) to be assigned to the object's Description property.


Reason property

Enumerated cause of the exception (XPathError class)

[Introduced in Sirius Mods 7.8]

Syntax

%xPathErrorReason = xPathError:Reason

Syntax terms

%reason This XPathErrorReason enumeration value describes the reason for the translation failure.
%XPathErr An XPathError object.

Usage notes

  • An XPathErrorReason enumeration may have one of the following values:
    SyntaxError
    A violation of the syntax of an XPath expression.
    EmptyResult
    There are no nodes matched by the XPath expression, and the method requires at least one matching node.
  • As with all enumerations, you use the ToString method to convert an enumeration value to a character string whose value is the name of the enumeration value.