http://www.perlmonks.org?node_id=1030448


in reply to Re^2: die through several evals
in thread die through several evals

... i'll stuck

Stuck where? Doing what?

I don't see anything getting "stuck"?:

sub mys{ print "??$_[0]??"; eval{ die 'bad stuff' if $_[0] eq 'die' }; };; print 'here'; eval{ mys( 'hello' ) }; print 'there'; eval{ mys( 'die' ) }; print 'over here';; here ??hello?? there ??die?? over here

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: die through several evals
by nyaapa (Novice) on Apr 24, 2013 at 17:33 UTC
    $SIG{ALRM} = sub { die "TIMEDOUT" }; my $sub = sub { warn "visible"; eval { # some big action in eval sleep(); }; warn "invisible"; }; # execute $sub with timeout alarm(1); $sub->();
    and get
    visible at -e line 1. invisible at -e line 1.

      That is exactly what is meant to happen.

      You wrap code in an eval in order to trap any error that might occur. If you then chose to not check for an error having occurred, then the code will continue as if no error had occurred.

      If you don't want the error to be ignored, you should either check for an error and rethrow if that is apppropriate; or don't use the eval in the first place.

      (And your 'visible'/'invisible' strings make no sense because: a) they are both visible; b) they should be!)

      I think that you'd better describe the overall goal you are trying to achieve, rather than looking to find a way to undo the very effect that the eval statement is designed to provide.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        i need function like with_timeout(&;$), it executes first argument with timeout. I can't use fork and storable/json, because of db handlers or something.
        also, i cant control passed sub for eval propagate.