Handling Exceptions

I am having trouble handling an exception.

Icons.Value(lvwMenu.RowTag(row)) Icons is a dictionary object and the key I am looking for may or may not exist. Why is the code below not catching the exception, the compiler keeps catching it.

[code] //Draw in the icon
Dim tmpIcon as new Picture(DefaultIconSize,DefaultIconSize)
tmpIcon = Icons.Value(lvwMenu.RowTag(row))

Return true

Exception err
if err isa KeyNotFoundException then
MsgBox “You tried to access a nonexistent item!”
end if

For dictionary objects (or any other for that matter)… If I know a error is possible and can be trapped I handle it… and use Exception for “unexpected” errors

Dim tmpIcon as new Picture(DefaultIconSize,DefaultIconSize)
  if icons.haskey(lvwMenu.Rowtag(row)) then tmpIcon = Icons.Value(lvwMenu.RowTag(row))
  Return true

Use Dictionary.HasKey instead of relying on an exception.

I don’t know what you mean by “the compiler keeps catching it.”

If “Break on Exceptions” is checked in the Project menu, the debugger appears for any exceptions, even if they are caught later. The solution is to do what Kem suggests, turn off Break on Exceptions or use the pragma to temporarily turn it off:

#Pragma BreakOnExceptions Off

Ahh just what I was looking for and didn’t know it existed. Thanks a million