Error handling

Hello,

could someone please point me in the right direction here;

I got this from the language guide;

Exception err If err IsA OutOfBoundsException then MsgBox "The value: "+Str(line_index)+" is out of range!" end if

but not great explanation on how to use it

So I have done this;

[code] dim a as integer
dim anArray(-1) as string

for a=1 to max
if line_colours(line_index,a)="" then
exit for
end if

anArray=line_colours(line_index,a).split(":")
l(val(anArray(0))).linecolor=rgb(val(anArray(1)),val(anArray(2)),val(anArray(3)))

next

Exception err
If err IsA OutOfBoundsException then
MsgBox “The value: “+Str(line_index)+” is out of range!”
end if[/code]

AS i am currently in testing the array line_colour isn’t fully populated with every line yet so I sometimes get an outofbounds

but the above doesnt catch it and at runtime I get an error on

if line_colours(line_index,a)="" then

can someone help me catch this error so I can continue development?

Have a look at the example in http://documentation.xojo.com/index.php/Introspection

That helps you catch all errors, not just OutOfBounds

Set a breakpoint at the line and follow execution in the debugger - you can see the values for line_index and a so you’ll have a better idea why that line throws an error.

P.S. I think what you might want is the Try method here http://documentation.xojo.com/index.php/Try

[quote=114520:@David Smith]AS i am currently in testing the array line_colour isn’t fully populated with every line yet so I sometimes get an outofbounds

but the above doesnt catch it and at runtime I get an error on

if line_colours(line_index,a)="" then
can someone help me catch this error so I can continue development?
[/quote]
What is the error? OutOfBoundsException? If so, then your code definitely will catch it. Whether or not that works for your program flow, I can’t say. Note that if you are running in the debugger, it will stop on an exception even if you catch it (unless you have Project->Break on Exceptions turned off).

Considering you are just processing an array, there seems to be little need to rely on catching an exception to handle the flow. Just test the array index values to make sure they are in range.

Thanks for the replies :slight_smile:

the error is out of bounds

I knew it would throw a few out of bounds errors as I am in the process of populating a text file which is then read in to populate the array. I am doing it in stages so I can test that the latest entries are functioning properly, but to function fully other entries are called further in that I have not yet populated

I will give your recommendations a go when I am next able to (currently at work! & moving the mother inlaw at the weekend)

I will post back when I have done so :slight_smile:

This is where I am tripping up :slight_smile: I am running in debugger but have not made the above change :slight_smile:

Explains why it wasn’t working how I wanted it to! Thanks for the useful links on error handling I will certainly be adding these to my program to make it far more stable :slight_smile:

You can hit Resume and your exception code will run.