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

classic Classic list List threaded Threaded
3 messages Options
Philippe Roux Philippe Roux
Reply | Threaded
Open this post in threaded view
|

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

Hi,

In scilab-5 I used to save console output of script file execution in a
text file with "diary", this seems to fail in scilab-6, for new errors
types recently added (Syntax error, Unexpected token ).  Perhaps I
misunderstood something in try/catch statement , let's consider the file
bug_syntax_error.sce containing :

diary(0)
diary('file.txt','new');
try disp('let''s make an error')
    1!=0  // syntax error
catch
    disp('added to diary')
end
diary('file.txt','close')


execute this script with CTRL+SHIFT+E  or "exec" will not create file.txt


--> exec('bug_syntax_error.sce', -1)
à la ligne     4 du fichier exécuté bug_syntax_error.sce

    1!=0  // syntax error
     ^^
Erreur : Unexpected token '!'

--> mgetl file.txt

mgetl : Impossible d'ouvrir le fichier file.txt.

execute this script from scinotes with CTRL+E will give :


--> diary(0)

--> diary('file.txt','new');

--> try disp('let''s make an error')
  >     1!=0  // syntax error
  > catch
  >     disp('added to diary')
  > end
    1!=0  // syntax error
     ^^
Erreur : Unexpected token '!'

--> diary('file.txt','close')

--> mgetl file.txt
 ans  =

!                                      !
!                                      !
!--> try disp('let''s make an error')  !
!                                      !
!  >     1!=0  // syntax error         !
!                                      !
!  > catch                             !
!                                      !
!  >     disp('added to diary')        !
!                                      !
!  > end                               !
!                                      !
!    1!=0  // syntax error             !
!                                      !
!     ^^                               !
!                                      !
!Erreur : Unexpected token '!'         !
!                                      !
!                                      !
!                                      !
!--> diary('file.txt','close')         !


I also remark that those new errors (like bad comparisons 1=2  or bad
string delimiters mixing ' and " ) have no localization. This doesn't
happend with "old" errors (which have localization), replacing "1!=0"
with "ieee(0),1/0" I get :

--> exec('bug_syntax_error.sce', -1)

 let's make an error

 added to diary

--> mgetl file.txt
 ans  =

!                      !
!                      !
! let's make an error  !
!                      !
!                      !
!                      !
! added to diary       !


Best regards,

Philippe

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
amonmayr amonmayr
Reply | Threaded
Open this post in threaded view
|

Re: diary lost in try/catch statement .

Hello,

As a workaround, if you replace
     1!=0  // syntax error
with
     str="1!=0";
     evstr(str);
it seems to work as you expected.

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!

Antoine


Le 03/09/2018 à 11:48, philippe a écrit :

> Hi,
>
> In scilab-5 I used to save console output of script file execution in a
> text file with "diary", this seems to fail in scilab-6, for new errors
> types recently added (Syntax error, Unexpected token ).  Perhaps I
> misunderstood something in try/catch statement , let's consider the file
> bug_syntax_error.sce containing :
>
> diary(0)
> diary('file.txt','new');
> try disp('let''s make an error')
>      1!=0  // syntax error
> catch
>      disp('added to diary')
> end
> diary('file.txt','close')
>
>
> execute this script with CTRL+SHIFT+E  or "exec" will not create file.txt
>
>
> --> exec('bug_syntax_error.sce', -1)
> à la ligne     4 du fichier exécuté bug_syntax_error.sce
>
>      1!=0  // syntax error
>       ^^
> Erreur : Unexpected token '!'
>
> --> mgetl file.txt
>
> mgetl : Impossible d'ouvrir le fichier file.txt.
>
> execute this script from scinotes with CTRL+E will give :
>
>
> --> diary(0)
>
> --> diary('file.txt','new');
>
> --> try disp('let''s make an error')
>    >     1!=0  // syntax error
>    > catch
>    >     disp('added to diary')
>    > end
>      1!=0  // syntax error
>       ^^
> Erreur : Unexpected token '!'
>
> --> diary('file.txt','close')
>
> --> mgetl file.txt
>   ans  =
>
> !                                      !
> !                                      !
> !--> try disp('let''s make an error')  !
> !                                      !
> !  >     1!=0  // syntax error         !
> !                                      !
> !  > catch                             !
> !                                      !
> !  >     disp('added to diary')        !
> !                                      !
> !  > end                               !
> !                                      !
> !    1!=0  // syntax error             !
> !                                      !
> !     ^^                               !
> !                                      !
> !Erreur : Unexpected token '!'         !
> !                                      !
> !                                      !
> !                                      !
> !--> diary('file.txt','close')         !
>
>
> I also remark that those new errors (like bad comparisons 1=2  or bad
> string delimiters mixing ' and " ) have no localization. This doesn't
> happend with "old" errors (which have localization), replacing "1!=0"
> with "ieee(0),1/0" I get :
>
> --> exec('bug_syntax_error.sce', -1)
>
>   let's make an error
>
>   added to diary
>
> --> mgetl file.txt
>   ans  =
>
> !                      !
> !                      !
> ! let's make an error  !
> !                      !
> !                      !
> !                      !
> ! added to diary       !
>
>
> Best regards,
>
> Philippe
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>

--
+++++++++++++++++++++++++++++++++++++++++++++++++++++++

  Antoine Monmayrant LAAS - CNRS
  7 avenue du Colonel Roche
  BP 54200
  31031 TOULOUSE Cedex 4
  FRANCE

  Tel:+33 5 61 33 64 59
 
  email : [hidden email]
  permanent email : [hidden email]

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Philippe Roux Philippe Roux
Reply | Threaded
Open this post in threaded view
|

Re: diary lost in try/catch statement .

Le 03/09/2018 à 12:38, [hidden email] 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

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users