Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
Problems? Is your data what you think it is?
 
PerlMonks  

Catch all die in Perl?

by Anonymous Monk
on Jul 18, 2005 at 20:07 UTC ( #475869=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Great Monks,

I'm just about finished writing some automatic error logging and emailing modules for my department's scripts. I'm just thinking about how I can easily apply these to all the existing scripts without using or mail(@args); every time I want to check for an error. I would like to have it so that if any kind of error at all occurs when running the script, then the email will get sent and the error will get logged.

So is there an all encapsulating error checker in Perl? I heard "try" is now in Perl or maybe something with __DIE__? I'm pretty new to the language so thanks for the help!

Greg

Comment on Catch all die in Perl?
Download Code
Re: Catch all die in Perl?
by friedo (Prior) on Jul 18, 2005 at 20:21 UTC
    You can install a custom handler in %SIG which will catch all fatal errors:

    BEGIN { $SIG{__DIE__} = sub { mail( $_[0] ) }; }

    That will send the die message to your mail routine. Alternatively, if you don't want to catch all dies, check out the block form of eval.

      Thanks a ton, that code chunk is just what I was looking for!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://475869]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (16)
As of 2014-04-18 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (466 votes), past polls