[Scilab-users] diary lost in try/catch statement .

philippe rouxph.22 at gmail.com
Mon Sep 3 19:08:20 CEST 2018


Le 03/09/2018 à 12:38, amonmayr at laas.fr a écrit :
> Hello,
> 
> As a workaround, if you replace
>     1!=0  // syntax error
> with
>     str="1!=0";
>     evstr(str);
> it seems to work as you expected.

Yes the bug disappear with execstr ? In fact my example wasn't clear
enough, here is a better one showing my problem. I have a script nammed
bugged.sce

disp('let''s make an error')
ieee(0);1/0  // syntax error

//and I want to test it with and auxiliary script :

unix("rm file.txt")// linux only
diary(0)
try diary('file.txt','new');
exec('bugged.sce',3);
diary('file.txt','close');
catch
    disp('added to diary')
    [str,n,line,func]=lasterror();
    printf(" error %d line %d in %s\n error message :\n
%s\n",n,line,func,str)
end
diary('file.txt','close');

//then I get the expected file.txt


--> disp('let''s make an error')

 let's make an error

--> ieee(0);1/0;// syntax error

 added to diary
 error 999 line 0 in exec
 error message :
 Division par zéro...

//now replace bugged.sce with

disp('let''s make an error')
1!=0  // syntax error

//then I get a wrong file file.txt


 added to diary
 error 999 line 4 in
 error message :
 1!=0;// syntax error

because the diary before the error is lost ! The problem occurs only
with "syntax error" :

'l'apostrophe'
1=2
1!=0


not with old errors like :

ieee(0);1/0
rand(2,2)*rand(3,3);
> 
> Anyway, I think the try/catch structure can catch errors occurring at
> runtime (like division by zero, etc ...), but not syntax errors.
> You are supposed to write syntactically correct Scilab!

my goal is to retrieve errors automatically from scripts with bugs (for
example for automatic testing of scripts I didn't wrote myself ) using
lasterror()  in the catch statement.

Best Regards,

Philippe




More information about the users mailing list