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

The LABEL search algorithm seems to fail when invoked in a signal handling context

Ah, that's very good information to have.

That idea was hackish enough for me that I've never actually tried to use it. Thanks for testing it.

Here's a crazy idea I'd never use myself, either:

{ package Medusa; # Fatal to look at use Carp 'croak'; use overload( '""' => sub { die $_[0] } ); sub new { my $self = 0; return bless \$self; } } my $timed_out = 0; eval { local $SIG{ALRM} = sub { warn "Time's up!\n"; die Medusa->new(); }; alarm( $seconds ); do_work(); alarm( 0 ); 1; } or do { alarm( 0 ); die $@ if "Medusa" ne ref($@); $@ = ''; $timed_out = 1; };

It works when tested on:

sub do_work { eval { eval { my $word = $ENV{WORD} || 'a'; $word++ while $word ne 'interrupt'; warn "Got: $word\n"; }; if( $@ ) { warn "Ignoring failure.\n"; } 1 } or do { my $e = $@ || 'Unknown error'; warn "Failed: $e\n"; }; } my $seconds = 2;

But that isn't a guarantee that every 'eval' will try to look at $@ after it fails. :)

- tye        

Replies are listed 'Best First'.
Re^4: die through several evals (last words)
by nyaapa (Novice) on Apr 24, 2013 at 09:27 UTC
    very good idea, but i have a guarantee, that sometimes they ignore error-code checking =(