Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hey.

I was browsing through the perldocs and saw this thing called $SIG{__DIE__}, which looked quite cool. In my script I had already implemented by redirecting STDERR to a file with magic open, but my one problem with this was that dies got printed to the logfile also, and not to the screen. I wanted them to go to both the screen and the logfile. So I thought, "COOL", and quickly added this line:

$SIG{__DIE__} = sub { print @_; die @_ };

Run it, everything was cool for a while. Then suddenly, alas. My code depends on some modules (the cause seems to be the URI module), and my __DIE__ handler was getting invoked by a module - inside an eval, that's why I never saw it before. die knows not to print it because it's being caught. print doesn't.

My guess is that I'll have to find an alternate way to do this. If so, can anyone suggest one? Or is there some way (hopefully not too magical) that I can find out whether my __DIE__ hook got called from inside an eval? It seems to me that a more effective design for this hook would be to make it not get called at all if it was inside one.

Thanks, Amoe.

--
my one true love

In reply to die hooks, signal handlers and eval, all mixed up by Amoe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found