Log in

View Full Version : Try-catch in Simba?



djborec
09-08-2012, 11:32 AM
Hello, I need to read some numbers from screen, I managed to read them and then I use StrToInt to convert them into Integer.

However ,the number that I am reading can be anything from 0 to 99999 so sometimes StrToInt returns error ,because OCR sometimes return String that is not number. (_9) for example or something.

So is there try-catch for SIMBA,so I can avoid to have script stopped ,because of this error.

weequ
09-08-2012, 11:35 AM
I think so but I'm not sure because I have never used. However you could use GetNumbers(String) and after that only use StrToInt if the length of the string is above zero.

riwu
09-08-2012, 11:41 AM
Use 'Try' instead.
Eg.
Try
StrToInt(NumInString);
Except
//some procedure to grab the number again? or Exit depending on your script structure.
end;
This will prevent a runtime error terminating the script.

djborec
09-08-2012, 11:43 AM
riwu, I have been looking for this ,thanks

masterBB
09-08-2012, 11:50 AM
A better way would be StrToIntDef(NumInString, -1);

This would return -1 when the number couldn't be read.

Master BAW
09-08-2012, 11:09 PM
I have a similar question: my script crashes when it does something wrong with this function.

DTMFromString

is it possible to try+except with this function? I don't want my script to crash when I'm away

Geo
09-08-2012, 11:31 PM
Some good suggestions above.

You could also use

result := ExtracFromStr(GetTextAtExWrap(), numbers)


then convert to an int with


StrToInt(result)

riwu
09-09-2012, 01:29 AM
I have a similar question: my script crashes when it does something wrong with this function.

DTMFromString

is it possible to try+except with this function? I don't want my script to crash when I'm away
How did DTMFromString cause a runtime error? If you think the problem definitely lies with it, you probably you didn't free the DTM and hence the memory leak caused the script to crash.

Master BAW
09-09-2012, 10:33 AM
How did DTMFromString cause a runtime error? If you think the problem definitely lies with it, you probably you didn't free the DTM and hence the memory leak caused the script to crash.

It was probably because I ran multiple of the same script in the same simba. In different simba's it works and doesn't crash on this function. (I know it crashes on this function because I see this function marked in orange in the script everytime the script has stopped)
but I didn't see an error yet because other scripts in the same simba continue and put text in the debug log...

anyway I am using multiple simba's now and I believe it's fine now. If I get another error like it I WILL see the error, and then I will post it here :)