ItemNotFound class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 7: Line 7:
   
   
The class's only method is the <var>[[New_(ItemNotFound_constructor)|New]]</var> constructor, which you would typically use with a <var class="product">User Language</var> [[Throw]] statement to produce an <var>ItemNotFound</var> exception.  For example:
The class's only method is the <var>[[New_(ItemNotFound_constructor)|New]]</var> constructor, which you would typically use with a <var class="product">User Language</var> [[Throw]] statement to produce an <var>ItemNotFound</var> exception.  For example:
<p class="code"> [[throw]] %(itemNotFound):new
<p class="code">throw %(itemNotFound):new
</p>
</p>
   
   
When working with the collection searching methods, remember that an exception is thrown only if there is a catcher for the exception. For example, if you expect one or no matches from your search, you might specify a block like the following:
Remember that catching an exception requires a <var>[[Catch statement|Catch]]</var> statement; if an exception condition occurs outside a
<p class="code"> [[try]] %terminationInfo =  -
<var>Catch</var> for it, the request is cancelled.
    %terminationList:findNextItem (eq(custId, %custid)
For example, if you expect one or no matches from your search, you might specify a block like the following:
    ... process the termination info
<p class="code">[[try]] %terminationInfo =  -
[[catch]] itemNotFound
    %terminationList:findNextItem (eq(custId, %custid)
end try
  ... process the termination info
[[catch]] itemNotFound
end try
</p>
</p>
   
   
Line 49: Line 51:
{{Template:ItemNotFound:New subtitle}}
{{Template:ItemNotFound:New subtitle}}


This callable constructor generates an instance of an <var>[[ItemNotFound_class|ItemNotFound]]</var> exception. The <var>New</var> method format follows:
This [[Notation conventions for methods|callable]] constructor generates an instance of an <var>[[ItemNotFound_class|ItemNotFound]]</var> exception. The <var>New</var> method format follows:


<h3>Syntax</h3>
<h3>Syntax</h3>
Line 58: Line 60:
<td>An <var>ItemNotFound</var> %variable which will refer to the newly created object.
<td>An <var>ItemNotFound</var> %variable which will refer to the newly created object.
</td></tr>
</td></tr>
<tr><th><var>%(ItemNotFound)</var></th><td>The class name in parentheses denotes a shared method.</td></tr>
<tr><th><var>%(ItemNotFound)</var></th><td>The class name in parentheses denotes a shared method. <var>New</var> can also be invoked via an <var>ItemNotFound</var> object variable, which may be <var>Null</var>.</td></tr>
</table>
</table>




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

Revision as of 00:09, 10 June 2011


An ItemNotFound exception indicates that a collection object search located no collection items that satisfy the selection criterion specified in the collection method that invoked the search. There are several searching methods, but only those that return a single found item produce an ItemNotFound exception.

This exception class has no properties. It is simply a notification that a valid search found no items that met the selection criterion.

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

throw %(itemNotFound):new

Remember that catching an exception requires a Catch statement; if an exception condition occurs outside a Catch for it, the request is cancelled. For example, if you expect one or no matches from your search, you might specify a block like the following:

try %terminationInfo = - %terminationList:findNextItem (eq(custId, %custid) ... process the termination info catch itemNotFound end try

On the other hand, if you always expect a match, 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 a test for a zero result. Try generates no quads other than the branch around the catch block if the search succeeds. And in fact, you could put a Try around a loop and use the ItemNotFound exception to exit the loop:

%i = 0 try repeat forever %i = %colla:findNextItemNumber(<criterion>), start=%i) %obj = %colla(%i) ... process the object end repeat catch itemNotFound end try

The ItemNotFound class is available as of version 7.6.


The ItemNotFound methods

The following are the available ItemNotFound class methods.

MethodDescription
NewCreate a new ItemNotFound object

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


New constructor

Create a new ItemNotFound object (ItemNotFound class)

This callable constructor generates an instance of an ItemNotFound exception. The New method format follows:

Syntax

%itemNotFound = [%(ItemNotFound):]New

Syntax terms

%itemNotFound An ItemNotFound %variable which will refer to the newly created object.
%(ItemNotFound)The class name in parentheses denotes a shared method. New can also be invoked via an ItemNotFound object variable, which may be Null.