A more "perl" approach is to do:
use CGI::Carp qw(fatals_to_browser);
This will redirect fatal errors to the browser, avoiding those non-descript 500 server errors. See here for details (http://search.cpan.org/~lds/CGI.pm-3.10/CGI/Carp.pm).
I don't know what the "best practices" are, but these two steps typically get me enough to debug most errors.
Sean
----- Original Message ----- From: "Siegfried Heintze" <[EMAIL PROTECTED]>
To: <beginners-cgi@perl.org>
Sent: Monday, May 16, 2005 5:16 PM
Subject: Recommended approaches for exceptions, stacktraces, error messages
Is anybody (perhaps book authors) promoting a "best practices" for perl CGI
programming?
I've been doing the use warning; use strict; use CGI; # this is from memory, but you get the idea. my $q = CGI->new; my $html = ""; eval { $html .= " <p> $data </p>"; $html .= "<div> more stuff $data2 </div>"; $broke || die "something broken"; } if($@){ print $q->header(), "Error: $@"; } else{ print $q->header(), $html; }
Should I be using the exception class?
Should I be using Carp::Croak? What will it buy me?
How can I get stack traces?
With ActiveState Perl 5.8+ I never get anything for $@ with my large
programs consisting of 8K lines of perl. I just get the Apache HTTPD error
message that there is an server internal error. It seems to work much better
when I single step thru trivial examples (like the above) in the debugger.
I'm wondering if my problem is that I'm not using the exception class.
Thanks, Siegfried
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>