ItemNotFound class: Difference between revisions
m (1 revision) |
m (tags and edits) |
||
Line 1: | Line 1: | ||
<!-- ItemNotFound class --> | <!-- ItemNotFound class --> | ||
An ItemNotFound exception indicates that a collection object search | An <var>ItemNotFound</var> 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. | ||
located no collection items that satisfy the selection criterion | There are several methods for [[Collections#Searching a collection|"searching a collection"]], but only those that return a single found item produce an <var>ItemNotFound</var> exception. | ||
specified in the collection method that invoked the search. | |||
There are several methods for [[Collections#Searching a collection|searching a collection]], | |||
but only those that return a single found item produce an ItemNotFound exception. | |||
This exception class has no properties. | This exception class has no properties. It is simply a notification that a valid search found no items that met the selection criterion. | ||
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 | 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: | ||
you would typically use with a User Language Throw statement | <p class="code"> [[throw]] %(itemNotFound):new | ||
to produce an ItemNotFound exception: | |||
<p class="code"> throw %(itemNotFound):new | |||
</p> | </p> | ||
When working with the collection searching methods, remember that | 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: | ||
an exception is thrown only if there is a catcher for the exception. | <p class="code"> [[try]] %terminationInfo = - | ||
For example, | |||
if you expect one or no matches from your search, you might specify | |||
a block like the following: | |||
<p class="code"> try %terminationInfo = - | |||
%terminationList:findNextItem (eq(custId, %custid) | %terminationList:findNextItem (eq(custId, %custid) | ||
... process the termination info | ... process the termination info | ||
catch itemNotFound | [[catch]] itemNotFound | ||
end try | end try | ||
</p> | </p> | ||
On the other hand, if you always expect | 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 <var>Try/Catch</var>. | ||
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. | The <var>Try/Catch</var> approach is slightly more efficient than a test for a zero result. <var>[[Try]]</var> generates no quads other than the branch around the catch block if the search succeeds. And in fact, you could put a <var>Try</var> around a loop and use the <var>ItemNotFound</var> exception to exit the loop: | ||
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: | |||
<p class="code"> %i = 0 | <p class="code"> %i = 0 | ||
try | [[try]] | ||
repeat forever | repeat forever | ||
%i = %colla:findNextItemNumber(<criterion>), start=%i) | %i = %colla:findNextItemNumber(<criterion>), start=%i) | ||
Line 44: | Line 27: | ||
... process the object | ... process the object | ||
end repeat | end repeat | ||
catch itemNotFound | [[catch]] itemNotFound | ||
end try | end try | ||
</p> | </p> | ||
The methods in this class are listed at "[[List of ItemNotFound methods]]". | The methods in this class are listed at "[[List of ItemNotFound methods]]". | ||
The <var>ItemNotFound</var> class is available as of <var class="product">[[Category:System exception classes]]</var> version 7.6. | |||
[[Category:System exception classes]] | [[Category:System exception classes]] | ||
Revision as of 06:36, 22 April 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 methods for "searching a collection", 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
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:
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 methods in this class are listed at "List of ItemNotFound methods".
The ItemNotFound class is available as of version 7.6.