XPathError class: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 38: | Line 38: | ||
{{Template:XPathError:CharacterPosition subtitle}} | {{Template:XPathError:CharacterPosition subtitle}} | ||
< | <h3>Syntax</h3> | ||
{{Template:XPathError:CharacterPosition syntax}} | {{Template:XPathError:CharacterPosition syntax}} | ||
<h4>Syntax terms</h4> | <h4>Syntax terms</h4> | ||
Line 53: | Line 53: | ||
{{Template:XPathError:Description subtitle}} | {{Template:XPathError:Description subtitle}} | ||
< | <h3>Syntax</h3> | ||
{{Template:XPathError:Description syntax}} | {{Template:XPathError:Description syntax}} | ||
<h4>Syntax terms</h4> | <h4>Syntax terms</h4> | ||
Line 69: | Line 69: | ||
Each argument to <var>New</var> sets the value of the corresponding property of the newly constructed <var>XPathError</var> object. | Each argument to <var>New</var> sets the value of the corresponding property of the newly constructed <var>XPathError</var> object. | ||
< | <h3>Syntax</h3> | ||
{{Template:XPathError:New syntax}} | {{Template:XPathError:New syntax}} | ||
<h4>Syntax terms</h4> | <h4>Syntax terms</h4> | ||
Line 90: | Line 90: | ||
{{Template:XPathError:Reason subtitle}} | {{Template:XPathError:Reason subtitle}} | ||
< | <h3>Syntax</h3> | ||
{{Template:XPathError:Reason syntax}} | {{Template:XPathError:Reason syntax}} | ||
<h4>Syntax terms</h4> | <h4>Syntax terms</h4> | ||
Line 110: | Line 110: | ||
requires at least one matching node.</td></tr> | requires at least one matching node.</td></tr> | ||
</table> | </table> | ||
As with all enumerations, you use | '''Note:''' As with all enumerations, you use | ||
the <code>ToString</code> method to convert an enumeration value to a | the <code>ToString</code> method to convert an enumeration value to a | ||
character string whose value is the name of the enumeration value. | character string whose value is the name of the enumeration value. |
Revision as of 23:03, 17 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.
Method | Description |
---|---|
CharacterPosition | Position of character at of before which the error occurred |
Description | Brief description of the exception |
New | Create a new XPathError object |
Reason | Enumerated cause of the exception |
The methods in the class are described in the subsections that follow. In addition:
- "Notation conventions for methods" has information about the conventions followed.
- "XPathError methods syntax" is a single page that contains the syntax diagrams of all the methods in the class.
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
%number | The position of the character at which the exception was thrown. |
---|---|
xPathError | An XPathError object. |
Description property
Brief description of the exception (XPathError class)
[Introduced in Sirius Mods 7.8]
Syntax
%string = xPathError:Description
Syntax terms
%string | A string to receive the description of the exception. |
---|---|
xPathError | 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
%xPathError | A reference to an instance of an XPathError object. |
---|---|
%(XPathError) | The class name in parentheses denotes a shared method. |
Reason | This name required parameter is an XPathErrorReason enumeration value which specifies the value to be assigned to the exception object's Reason property.
The Reason parameter is not optional. |
Description | This name required parameter specifies the string value (string) to be assigned to the object's Description property. |
CharacterPosition | This name required parameter specifies the numeric value (number) to be assigned to the object's CharacterPosition property. |
Reason property
Enumerated cause of the exception (XPathError class)
[Introduced in Sirius Mods 7.8]
Syntax
%xPathErrorReason = xPathError:Reason
Syntax terms
%xPathErrorReason | This XPathErrorReason enumeration value (see below) describes the reason for the translation failure. |
---|---|
xPathError | An XPathError object. |
XPathErrorReason enumeration
An XPathErrorReason enumeration may have one of the following values:
SyntaxError | A violation of the syntax of an XPath expression. |
---|---|
EmptyResult | No nodes are matched by the XPath expression, and the method requires at least one matching node. |
Note: 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.