in reply to Eval not catching Dies

Are you trying to catch the die() after the eval()? If so, my best guess is the fact that the perldoc for alarm says that the die() in the sig handler must terminate with a newline. So you just might need this instead (just a guess, I really don't know if this will help at all). Note that I took out the state handler. You really shouldn't need that unless you need to maintain state further.

my $cmd; eval { local $SIG{'ALRM'} = sub { die "DIED\n" }; local $SIG{'CHLD'} = sub { die "DIED\n" }; $cmd = <STDIN>; }; if ($@) { die $@ eq "DIED\n" ? "We died from a sig handler\n" : "Other death: $@\n"; }

Replies are listed 'Best First'.
Re: Re: Eval not catching Dies
by Anonymous Monk on Dec 08, 2003 at 19:02 UTC
    > Are you trying to catch the die() after the eval{}?
    No. The purpose of the die() is to 'terminate' the read from STDIN. Outside the eval, I don't care if it died. I just check to see if the user input anything for $cmd, and then I process that.
    > perldoc for alarm says that the die() in the sig handler must terminate with a newline
    Okay. I'll add one. However, that begs the question of "Why does it have to have a newline?" I tested alarm handlers before without newlines and they work. This looks like an artifact to me.
      Well, I figured out the 'newline' issue. Adding a newline at the end of the die() text suppresses the addition of 'at xxx line #.'. The newline comment in the alarm code example is given because of the 'eq "alarm\n" conditional further down. Without the newline, the same conditional can be realized using '=~ /^alarm/'. Therefore, the newline is not germane to my problem. (Although, I did add one.)