SRL Archive - Help

Math Errors...


Xtensity

2010-08-07 17:02:23

is there any way I can make a script continue even if it runs into a math error?

For instance, on my Ti-84 calculator, if the equation tries to divide by zero or something, or square root a negative, it wont refuse to continue on trying the other numbers..


This is an issue that's preventing me from progressing on my current script, since the numbers I need are scattered throughout the equation…

For instance… the working x values could be anywhere in 1-100. Say there are only 5 working x values.. the other 95 x values would return a math error and crash the script.

is there any way around this?

Cigue

2010-08-07 17:39:47

well, the way I'd do it is to put the following
if IntInArr(TheIntegerThatCouldFail, ArrayOfWorkingValues) then
Result := OperationThatSometimesFail;
else
Result := -1;

You could also ask more experienced scripters about try..except..finally :)

EDIT : As an example, you could put x as the integer that could fail, [2, 4, 6, 8] as working values and 2/(x-y) as the operation that could fail.

Killerdou

2010-08-07 18:01:17

Or you could use "try except" (should be in a tutorial somewhere)

Narcle

2010-08-07 18:17:05


try
your code
except
end;

like that

Xtensity

2010-08-08 04:32:10

Hm, I actually have absolutely no experience with try or except, would be something new to learn.

I'll go look for a tutorial…. and Cigue, if I knew the array of working values then I wouldn't have to cycle through a large number of variables to find working variables.