Page 1 sur 1

try... catch

Publié : mar. mars 20, 2018 4:22 pm
par belanger
I may be doing something wrong, but I'm having trouble getting "try ... catch" to work correctly.

Using an example from the manual, I entered

Code : Tout sélectionner

try{A:=idn(2)*idn(3)} catch(erreur) {print("l'erreur est "+erreur)}
and instead of

Code : Tout sélectionner

"l’erreur est * Invalid dimension"
I get

Code : Tout sélectionner

:1: syntax error, unexpected T_SYMBOL line 1 col 46 at l
I noticed that if I try

Code : Tout sélectionner

try{A:=idn(2)*idn(3)} catch(erreur) {print(5)}
then 5 gets printed, as it should, but if I try

Code : Tout sélectionner

try{A:=idn(2)*idn(3)} catch(erreur) {print("5")}
I get

Code : Tout sélectionner

:1: syntax error, unexpected T_NUMBER line 1 col 46 at 5
Meanwhile, both print(5) and print("5") work fine by themselves, not in a catch block.
It looks like print is not working with strings in the catch block.

Finally, I tried

Code : Tout sélectionner

try{A:=idn(2)*idn(3)} catch(err) {myerr := err}
and got

Code : Tout sélectionner

try_catch([(A:=idn(2)*idn(3)),err,(myerr:=err)]) 
 Error: Invalid dimension
and then

Code : Tout sélectionner

print("The error is " + myerr)
gives

Code : Tout sélectionner

The error is try_catch([(A:=idn(2)*idn(3)),err,(myerr:=err)]) 
 Error: Invalid dimension
So that sort of works (although it looks like the error string is a bit long).

Jay

Re: try... catch

Publié : mar. mars 20, 2018 7:45 pm
par parisse
I think it's a side effect of some optimizations I made for some operations like *, I will investigate tomorrow.

Re: try... catch

Publié : mer. mars 21, 2018 9:45 am
par parisse
Should be fixed in source code. I'll update binaries probably next week.