http://qs321.pair.com?node_id=42379


in reply to BEGIN, END, eval and die.

The $@ variable is only set by the eval code if it somehow fails. In your last example, you don't use eval to "catch" this die, so $@ will not be set.

However, even if you used eval, this will not work for your END-block. You might want to try to install a $SIG{__DIE__} handler instead. Using that to set a variable or something similar, so that you can access the information within the END-block.

$SIG{__DIE__} = sub { our @reason = @_ }; eval { die "Let's Try to die." }; END { our @reason; if (@reason) { print "We caught a call to die: @reason\n"; } }

Autark.