This file contains information about the following subjects:
The exceptions defined and used in the Collection Class Library are shown in the table below (classes defined by the Collection Class Library are shown in bold). They all derive from IException, directly or indirectly.
Hierarchy of Exceptions Defined and Used by the Collection Classes
IException ICollectionResourceException ICollectionLockException ICollectionUnlockException ICollectionLockTimeOutException* IPreconditionViolation IChildAlreadyExistsException ICursorInvalidException IEmptyException IFullException IIdenticalCollectionException InvalidReplacementException IKeyAlreadyExistsException INotBoundedException INotContainsKeyException IPositionInvalidException IRootAlreadyExistsException IResourceExhausted IOutOfMemory
*not on .
A precondition of a called function is a condition that the function requires to be true when it is called. The calling function must assure that this condition holds. The called function implementation may assume that the condition holds without further checking it. If a precondition does not hold, the called function's behavior is undefined.
If you want to make your programs more robust and to locate errors in the test phase, the functions your program calls should check to ensure that their preconditions hold. The Collection Class Library enables this checking through macro definitions. Because this checking often requires significant overhead, it is turned off by default. You need only use it while you are testing the system and verifying that preconditions are always met.
A call to a function that violates the function's preconditions has two possible results:
The Collection Classes include the following precondition-violation exceptions:
1. Every time a cursor is created, you must specify the collection that it belongs to. If a function takes a cursor as an argument (such as add, setToFirst, and locate), the function can only be applied to the collection that the cursor belongs to. If the function is applied to another collection, the ICursorInvalidException results.
2. If a function takes a cursor as an input argument (such as elementAt, removeAt, and replaceAt), the cursor must be valid. A cursor is valid if it actually refers to some element contained in the collection. You can use the isValid function to determine if a cursor is valid.
The following lists the causes of the other exceptions defined or used by the Collection Classes:
System failures and restrictions are different from precondition violations. You cannot usually anticipate them, and you have no opportunity to verify that such situations, for example storage overflow, will not occur. These exceptions need to be checked for, and an exception should be thrown if they occur.
Introduction to the
Collection Classes
Collection
Characteristics
Adding Elements
Removing
Elements
Replacing
Elements
Thread Safety and the
Collection Classes
Enabling
Exception Checking
Implementing
Bounded Collections
Guard
Objects
Instantiating a Guard Object
Using
Guard Objects
Adding an
Element to a Collection
Removing an
Element from a Collection
Using
Cursors to Locate and Access Elements
Using
Cursors to Iterate Over a Collection
Using
allElementsDo and Applicators to Iterate Over a Collection
Cursors vs.
Exception Handling
Instantiating
the Collection Classes