Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This is a great question, and I look forward to others replies to it. The big problem is that there is no one size fits all answer to this question. If your perl is a CGI script you don't want to die before you've printed out some error message. In other cases die is just fine. If you've got a database connection open you may want to clean up so an eval block is crucial. For the purposes of simple CGI's I've used the following general purpose "bomb" routine:
#--------------------------------------------------- # subroutine bomb # a somewhat ungracefull way to end the execution of the cgi sub bomb { my $error_text = shift; print "\n<B>Ho Boy! A nasty error has occured:</B> "; #extra \n to close off the HTTP header print $error_text; print "\n"; my @mail; if ($MAIL_BOMB_LIST ne '') { &printbomb(\@mail,$error_text); @BombRecipients = split (/,/, $MAIL_BOMB_LIST); my $submission = join '',@mail; $submission = "\n\n".$submission; $sent = &send_mail ($BombSMTPServer, $submission, 'CGI_Bomber@', "CGI $ENV{'SCRIPT_NAME'} bombed.", $BombReplyto, @BombReci +pients); } exit; } # load error message and backtrace into @$array sub printbomb { my $array = shift; my $message = shift; my($syserror) = $!; push @$array, <<"EOM"; The CGI script $ENV{'SCRIPT_NAME'} seems to be having trouble! Error Message: $message Sys Error is: $syserror EOM my $i = 2; # start back 2 so as not to print bomb & printbomb s +tack frames. push @$array, "Backtrace:\n"; push @$array, " Subroutine name | Line | + File \n"; push @$array, "----------------------|------|--------------------- +----------------------------\n"; while(($pack,$file,$line,$subname) = caller($i++)) { push @$array, sprintf("%21s |%5s |%50s\n",$subname,$line,$file +); } }
This code is obviously not the neatest, but it's very nice for debugging. It simply prints out the error message, but then e-mails the stack backtrace to the emails in the global $MAIL_BOMB_LIST

-I went outside... and then I came back in!!!!

In reply to Re: Exceptions and Return Codes by Henri Icarus
in thread Exceptions and Return Codes by kschwab

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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2023-12-11 23:15 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (41 votes). Check out past polls.