Handling a Mystery Out of Bounds Exception

I had a report today from a user, the report (generated by the app) said an OutOfBounds exception happened in this method where the global variable Erln=6 :


Erln=4
if WhichShow=nil then return false
Erln=6
if Cid<0 or Cid>UBound(WhichShow.CatList) then return false 'Cid is an integer, CatList is an array that is a property of WhichShow

Code execution went through the first three lines (through Erln=6) without raising an exception. There aren’t any threads altering the dimensions of CatList, though it’s remotely possible that WhichShow could go nil during execution if the application quits.

How could an OutOfBounds exception have happened here? If checking for bounds isn’t enough to prevent the exception from happening, then what would be?

I can’t see putting Try/Catch/EndTry statements around every single line of code…

Thoughts? Suggestions? I’m stumped…:frowning:

I am doubtful that is the actual line creating the exception…
if the error is “OutOfBounds” then it is happening elsewhere… as UBOUND simply returns what the bound IS
are you sure that Cid isn’t >0 and <Ubound and the error is farther along?

OutOfBounds normally occurs when you attempt to access an element that is well “out of bounds” :slight_smile:

[quote=353683:@Dave S]I am doubtful that is the actual line creating the exception…
if the error is “OutOfBounds” then it is happening elsewhere… as UBOUND simply returns what the bound IS
are you sure that Cid isn’t >0 and <Ubound and the error is farther along?

OutOfBounds normally occurs when you attempt to access an element that is well “out of bounds” :)[/quote]

However, the line of code after this is actually “Erln=8”, so if the error occurred past this point, the Erln would have changed.

Maybe the error is in the exception reporting code? I’ll check that out.

I agree with Dave. It’s really happening elsewhere. See where the WhichShow array is getting modified. Events/Threads can really mess with you.