Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Answer: how do i trap the error generated by perl

( #86745=categorized answer: print w/ replies, xml ) Need Help??

Q&A > programs and processes > how do i trap the error generated by perl contributed by bikeNomad

You need to look at the discussions of die() and warn() and the %SIG hash. You can set up your own handlers for errors (via die) using $SIG{__DIE__} = sub { ... } and for warnings (via warn) using $SIG{__WARN__} = sub { ... }. See the perlvar and perlfunc manpages. You can also run code that you think might die inside an eval { } construction and keep your program from dying.
#!/usr/bin/perl -w use strict; $SIG{__DIE__} = sub { die("My error: ", @_); }; $SIG{__WARN__} = sub { warn("My warning: ", @_); }; warn("some warning"); die("aarggh!");

Comment on Answer: how do i trap the error generated by perl
Download Code
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2014-08-31 03:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls