jed-users mailing list

[2003 Date Index] [2003 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: read_mini, ^G returns Null_String


A while ago I wrote:


> s= read_mini( "pr", "de", "ok")
>
> If this runs and gets aborted (^G),
> a Null_String ("") is left on the stack.
>
> Tested workaround:
>
> static define t()
> {
>    variable s;
>
>    ERROR_BLOCK {
>       _clear_error();
>       pop();
>       NULL;
>    }
>    read_mini( "pr","de","ok");
>    s= ();
>    return s; % NULL if error or ^G
> }
>
> With other solutions I was not lucky. s= read_mini() seems to prevent
> to redefine s in the ERROR_BLOCK. Does this mean s gets finally defined
> by read_mini _after_ the ERROR_BLOCK runs?

Yes, I am now pretty sure this is the case:
If read_mini -- or any other evaluation of code, e.g. expression or
function --
produces a recoverable error condition, the execution thread switches to the
ERROR_BLOCK, and after execution of that -- provided _clear_error() is used
and no return is used within the ERROR_BLOCK  -- the execution will
resume _after_the_offending_code_.

In contrary, the documentation says: ... execution will resume
_at_the_next_statement_ ...
Needless to say, that I would like to improve the documentation about this.
Supposed I am not completly wrong of course ;)


Examples:

define t(){
%   ERROR_BLOCK { _clear_error();}
%   loop(1)
   $1= 1/0.;
} % will produce a nice 'divide by zero'

define t(){
   ERROR_BLOCK { _clear_error();}
%   loop(1)
   $1= 1/0.;
} % will produce a stack underflow, cause errorneous expression returns
nothing

define t(){
   ERROR_BLOCK { _clear_error();}
   loop(1)
   $1= 1/0.;
} % really clean -- error resuming after the loop-block

I think it gets obvious by this, that the information about what is returned
(i.e. left on stack) in case of an error or cancel is of special interest
when
using ERROR_BLOCKS. Second choice, I think, would be to use a
general stack-cleanup procedure; maybe necessary, if we have a block
with different potential code pieces, which may cause errors.


-- Klaus



--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2003 date index] [2003 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]