in reply to XML::Simple conflicts with $SIG{__DIE__}

Um, don't do that. Using a __DIE__ handler totally screws any exception handling (with eval blocks) inside the modules you use. One of the modules you're using must be trying to manage errors with exceptions, and you're breaking it by setting a global __DIE__ handler.
  • Comment on Re: XML::Simple conflicts with $SIG{__DIE__}

Replies are listed 'Best First'.
Re: Re: XML::Simple conflicts with $SIG{__DIE__}
by Matts (Deacon) on Apr 18, 2002 at 13:43 UTC
    Or perhaps more properly, any $SIG{__DIE__} handler you install should only ever be used to augment the exception and re-throw it. Anything else completely breaks perl's exception handling mechanism. Here's a working (and useful) example of a good $SIG{__DIE__} handler:
    local $SIG{__DIE__} = sub { my $err = shift; if (ref($err)) { die $err; } else { throw Exception::Unknown (error => $err); } };
    Implementation of the Exception::Unknown class is left as an exercise. Also note the use of local - so that if we're running under something like mod_perl we don't screw up everyone elses handler that might not want this effect.
Re: Re: XML::Simple conflicts with $SIG{__DIE__}
by broquaint (Abbot) on Apr 18, 2002 at 13:23 UTC
    All is clear, many thanks perrin!

    The problem is that XML::Parser::Expat does something which it is fully aware is potentially dubious, which is why it is within an eval(). Now normally die() would just set $@ and all would be well, but the custom $SIG{__DIE__} handler was printing out the error XML::Parser::Expat wanted kept quiet, which was the cause of my confusion.

    Here's a *very* simplified version of what was going on

    use strict; $SIG{__DIE__} = sub { print "something went wrong - $_[0]\n" }; eval { my $lexvar = *{"a string"}{IO}; }; # exceptions, shmexcetpions undef $@;
    So while any potential error was intentionally ignored, the custom $SIG{__DIE__} handler was announcing this FUD to the world.

    broquaint