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

Re^2: Stopping Module Croaking

by gellyfish (Monsignor)
on May 11, 2005 at 11:29 UTC ( #455952=note: print w/ replies, xml ) Need Help??


in reply to Re: Stopping Module Croaking
in thread Stopping Module Croaking

People keep saying this, but overlook that CGI::Carp has a convenient mechanism to control what gets sent to the browser with fatalsToBrowser activated:

#!/usr/bin/perl + use strict; + use CGI::Carp qw(fatalsToBrowser set_message); + + my $sub_message = sub { my ($message) = @_; if ($ENV{REMOTE_ADDR} eq '127.0.0.1') { print "Oops: $message"; } else { print "Unable to process, please try later" +; } }; + set_message($sub_message); + die "aiee!";
Of course you can use whatever condition you like to control whether the text of the die message gets displayed or not - a debugging flag or similar might make more sense in some circumstances.

fatalsToBrowser provides a simple mechanism for trapping exceptions in the code which might otherwise result in at best a confusing 500 status in the users browser, and the advantage of doing something like the above is that you can use the same code for debugging as you do in production thus reducing the possibility of introducing new bugs when removing diagnostic code.

You should bear in mind that not everyone has the luxury of access to the error logs when deploying a web application to production, indeed some servers (such as IIS) make it very difficult to get that information.

/J\


Comment on Re^2: Stopping Module Croaking
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-08-20 23:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (125 votes), past polls