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

Re: how do i trap the error generated by perl

by bikeNomad (Priest)
on Jun 08, 2001 at 00:46 UTC ( [id://86745]=note: print w/replies, xml ) Need Help??


in reply to how do i trap the error generated by perl

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!");

Log In?
Username:
Password:

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

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

    No recent polls found