Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: SIG, Modules, and Eval

by aitap (Curate)
on Aug 15, 2014 at 19:45 UTC ( [id://1097612]=note: print w/replies, xml ) Need Help??


in reply to SIG, Modules, and Eval

As should be obvious, we're trying to catch fatal errors gracefully to give them an "I'm sorry" page instead of just handing them an ugly "500" page from the web server.
Look at the code of CGI::Carp - it's implemented there. They check if the exception was thrown from an eval by examining $^S.

Replies are listed 'Best First'.
Re^2: SIG, Modules, and Eval
by kbrannen (Beadle) on Aug 16, 2014 at 03:41 UTC
    > Look at the code of CGI::Carp - it's implemented there. They check if the exception was thrown from an eval by examining $^S.

    Either I didn't make my self clear or you misunderstood or I misunderstand your comment. :) The issue is that the eval's are in modules not under my control; specifically, they're from CPAN if it matters. Those modules are essentially getting in my way and triggering my __DIE__ signal handler when I don't want that. They don't die, but they do trigger my handler uneccesarily.

    Kevin
      $SIG{__DIE__} = sub { return if $^S; ... print(STDERR $_[0]); exit($! || ($? >> 8) || 255); };
        I did something similar on one of my first tries to find out what was going on and to fix this. I looked at the call stack and if there wasn't a ".cgi" file in the list then assumed I was in the "compile" stage and just returned. Not as elegent as using $^S but it worked. If I had to do something like this, I like the $^S way better now that I know about it.

        In the end, I'd really like to know why I had to do anything like this. If we have code like:
        package X; BEGIN { whatever; } $main::SIG{__DIE__} = \&some_function; # when does this get run? sub new { ... }
        In what phase is that SIG handler assigned? I would have thought it was in an implied INIT, but the code acts like it's in an implied BEGIN. I ended up solving the entire issue by putting that line in an explicit INIT block, but why did I have to do that?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1097612]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found