Get tired of trying to figure out what went wrong in your CGI programs when you get a 500 Internal Server Error? Maybe you can't get to your error logs for one reason or another (often a problem on shared servers)? Here's an easy way to get those errors sent to your browser instead of a 500 Internal Server Error (provided you have set permissions on the CGI program correctly and it isn't an error due to that).

This comes in really handy when debugging, but shouldn't be a permanent fixture of your CGI programs in most cases. (You wouldn't want the script to dump out it's errors every time it encountered one when running an app in production mode-- it's embarrassing! It also isn't safe and could reveal information about your server or operating system that you don't want the public to know)

Go ahead and give it a try. Write a mini-program, even with syntax errors, put it on your server, chmod perms on it to 755 or mark it as "executable" on Windowse servers, and call it from the browser.

See also: CGI::Carp

# Put this code anywhere in your script. BEGIN { $SIG{'__DIE__'} = sub { print <<__WARN__ and exit 1 } } Content-Type: text/html; charset=ISO-8859-1\n Fatal Error in @{[(caller(2))[1]||__FILE__]} at ${\ scalar localtime } while responding to request from ${\ $ENV{'REMOTE_ADDR'} || 'localhost +' } ${\ join("\n",$!,$@,@_) } __WARN__

Replies are listed 'Best First'.
•Re: Perl CGI Tip: Send error messages to your browser
by merlyn (Sage) on Jan 10, 2004 at 04:14 UTC

      Wow! A reply from Randal Schwartz! Thanks merlyn.

      --
      Tommy Butler, a.k.a. TOMMY