KeyNotFoundException

From Xojo Documentation

Revision as of 19:13, 19 November 2009 by WikiSysop (talk) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Description

You tried to access an item in a Dictionary using a key that is not in the Dictionary.


Super Class

RuntimeException.

Examples

The following For loop produces a KeyNotFoundException error when the loop runs with the counter equal to 1. The value of 1 - which is a Variant, not an Integer - has just been removed.

d.Value(0)="Clark Kent"
d.Value(1)="Lois Lane"
d.Value(2)="Jimmy Olsen"
d.Remove(1)
For i=0 to d.Count-1 //fails when i=1
 ListBox1.Addrow d.value(i)
Next

To handle the error, add an Exception block to the end of the method, such as:

Exception err as KeyNotFoundException
MsgBox "You tried to access a nonexistent item!"


See Also

Dictionary, RuntimeException classes; Exception block.