ItemNotPresent class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
 
m (link repair)
 
Line 48: Line 48:
The methods in the class are described in the subsections that follow. In addition:
The methods in the class are described in the subsections that follow. In addition:
<ul>
<ul>
<li>[[Notation conventions for methods|"Notation conventions for methods"]] has information
<li>[[Notation conventions for methods]] has information about the conventions followed. </li>
about the conventions followed.  
<li>[[ItemNotPresent methods syntax]] is a single page that contains the syntax diagrams of all the methods in the class. </li>
<li>[[ItemNotPresent methods syntax|"ItemNotPresent methods syntax"]] is a single page that contains the syntax diagrams of all the methods in the class.
</ul>
</ul>


Line 69: Line 68:


<tr><th><var>[%(ItemNotPresent):]</var></th>
<tr><th><var>[%(ItemNotPresent):]</var></th>
<td>The class name in parentheses denotes a <var>[[Notation conventions for methods#Constructors|Constructor]]</var>. See [[#Usage notes|"Usage notes"]], below, for more information about invoking an <var>ItemNotPresent</var><var>Constructor</var>.</td></tr>
<td>The class name in parentheses denotes a <var>[[Notation conventions for methods#Constructors|Constructor]]</var>. See [[#Usage notes|Usage notes]], below, for more information about invoking an <var>ItemNotPresent</var><var>Constructor</var>.</td></tr>
</table>
</table>


===Usage notes===
===Usage notes===
<ul>
<ul>
<li>As described in [[Object variables#Using New or other Constructors|"Using New or other Constructors"]],<var>New</var> can be invoked with no object, with an explicit class name, or with an object variable in the class, even if that object is <var>Null</var>:<p class="code">%itemnp = new
<li>As described in [[Object variables#Using New or other Constructors|Using New or other Constructors]],<var>New</var> can be invoked with no object, with an explicit class name, or with an object variable in the class, even if that object is <var>Null</var>:<p class="code">%itemnp = new


%itemnp = %(ItemNotPresent):new
%itemnp = %(ItemNotPresent):new

Latest revision as of 21:31, 18 November 2014


An ItemNotPresent exception indicates that an explict or implicit NamedArraylist Item method requested a value not present on the NamedArrayList. NamedArraylist here can mean the NamedArraylist class, FloatNamedArraylist class, or UnicodeNamedArraylist class.

This exception class has no properties. It is simply a notification that requested item was not present on the NamedArrayList.

The class's only method is the New constructor, which you would typically use with a User Language Throw statement to produce an ItemNotPresent exception yourself. For example:

throw %(itemNotPresent):new

Remember that you catch an exception with the Catch statement; if an exception condition occurs outside a Catch for it, the request is cancelled. For example, if you think it is possible that a value is not on the NamedArraylist, you can do:

try %value = %valueList(%string) ... process the value catch itemNotPresent end try

On the other hand, if you always expect the item to be present, you might want a program crash to result if you are wrong about the match, so you could leave out a Try/Catch.

The Try/Catch approach is slightly more efficient than testing for a zero result with the Number (NamedArraylist function) function, Number (FloatNamedArraylist function), or Number (UnicodeNamedArraylist function)). Try generates no quads other than the branch around the Catch block if the item is present. If UseDefault is set to True for the NamedArraylist, an ItemNotPresent exception is never thrown. Using a default value for not-present items is more efficient but less flexible than catching an ItemNotPresent exception.

The ItemNotPresent class is available as of Sirius Mods version 8.0.

The most common use of the ItemNotPresent exception class is in NamedArraylists that are used as a cache for expensive-to-produce values or objects. For example, if %recordsets is a NamedArraylist of Recordset objects (in some file), the following is an example of how one might avoid doing a Find more than once for a specific value:

for %i from 1 to %keys:count %key = %key(%i) try %recordset = %recordsets(%key) catch itemNotPresent find records to %recordset key = %key end find %recordsets(%key) = %recordset end try end for

The ItemNotPresent methods

MethodDescription
NewCreate a new ItemNotPresent object

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


New constructor

Create a new ItemNotPresent object (ItemNotPresent class)

[Introduced in Sirius Mods 8.0]

This method generates an instance of an ItemNotPresent exception. The New method format follows:

Syntax

%itemNotPresent = [%(ItemNotPresent):]New

Syntax terms

%itemNotPresent An ItemNotPresent %variable which will refer to the newly created object.
[%(ItemNotPresent):] The class name in parentheses denotes a Constructor. See Usage notes, below, for more information about invoking an ItemNotPresentConstructor.

Usage notes

  • As described in Using New or other Constructors,New can be invoked with no object, with an explicit class name, or with an object variable in the class, even if that object is Null:

    %itemnp = new %itemnp = %(ItemNotPresent):new %itemnp = %itemnp:new