try... catch
Publié : 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
and instead of
I get
I noticed that if I try
then 5 gets printed, as it should, but if I try
I get
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
and got
and then
gives
So that sort of works (although it looks like the error string is a bit long).
Jay
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)}
Code : Tout sélectionner
"l’erreur est * Invalid dimension"
Code : Tout sélectionner
:1: syntax error, unexpected T_SYMBOL line 1 col 46 at l
Code : Tout sélectionner
try{A:=idn(2)*idn(3)} catch(erreur) {print(5)}
Code : Tout sélectionner
try{A:=idn(2)*idn(3)} catch(erreur) {print("5")}
Code : Tout sélectionner
:1: syntax error, unexpected T_NUMBER line 1 col 46 at 5
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}
Code : Tout sélectionner
try_catch([(A:=idn(2)*idn(3)),err,(myerr:=err)])
Error: Invalid dimension
Code : Tout sélectionner
print("The error is " + myerr)
Code : Tout sélectionner
The error is try_catch([(A:=idn(2)*idn(3)),err,(myerr:=err)])
Error: Invalid dimension
Jay