try... catch

Messages in english

Modérateur : xcasadmin

belanger
Messages : 59
Inscription : jeu. juil. 27, 2017 3:26 pm

try... catch

Message par belanger » mar. mars 20, 2018 4:22 pm

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

parisse
Messages : 5734
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: try... catch

Message par parisse » mar. mars 20, 2018 7:45 pm

I think it's a side effect of some optimizations I made for some operations like *, I will investigate tomorrow.

parisse
Messages : 5734
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: try... catch

Message par parisse » mer. mars 21, 2018 9:45 am

Should be fixed in source code. I'll update binaries probably next week.

Répondre