bsexton1qBob Sexton has asked for the wisdom of the Perl Monks concerning the following question:

My script works fine until the $size > $max and it has to execute the die.... Then I get an Internal Server error. I see no error, cna someone help??
if ($size > $max) { die"You have exceeded your limit of $max for the directory $email_addr +ess\n"; }

Replies are listed 'Best First'.
Re: die function error
by gjb (Vicar) on Dec 03, 2002 at 20:28 UTC

    die won't provide any feedback to the browser, just that an internal server error occured, so the observed behavior is perfectly normal.

    Have a look at CGI::Carp if you do want feedback to be sent to the browser.

    Hope this helps, -gjb-

      Unfortunately, I'm new to perl, and a little confused. What would cause the error. It only occurs when I hit the 'if routine.. I tried putting in use CGI::Carp; at the top of the script but no error was written to the error log. All I really want to do is print a message if the $max is exceeded and exit the script. Can you tell me how to replace the If.. statement to do the above??
        the perl die command prints to STDERR. normally, if you want some text to be sent back to the web page by your CGI script, use print, even if its a failure message. So:
        if ( error_condition ) { print error message to page; die error message to http server log; }
        (substitute appropriate text for the messages)
        CGI::Carp writes no error to the error log, because the errors are sent to STDOUT instead of STDERR.
        there may be flags to CGI::Carp to get the errors to STDERR also, but im no expert there...

        UPDATE:
        CGI::Carp does actually write to STDERR also, so that gets put in your error log too.
(bbfu) (CGI::Carp) Re: die function error
by bbfu (Curate) on Dec 03, 2002 at 23:06 UTC

    Add the following line to your CGI script. It will send all errors and warnings both to the log file and to the browser.

    use CGI::Carp qw/warningsToBrowser fatalsToBrowser/;

    bbfu
    Black flowers blossum
    Fearless on my breath

      I guess I'm stupid here. I changed the code to.
      if ($size > $max) { print "You have exceeded your limit of $max for the directory $email_a +ddr +ess\n"; }
      I still get the internal server error, only when the $max is exceeded.

        You're probably not returning valid HTTP response headers. Use CGI and print $cgi->header().

        bbfu
        Black flowers blossum
        Fearless on my breath