On Sun, 24 Mar 2002 13:44:59 -0400 (AST)
Jeff MacDonald <[EMAIL PROTECTED]> wrote:
>HI,
>
>> calling warn(). Finally, it lets me write things such as:
>> $dbh->prepare("SELECT * FROM Table") or die("Unable to select
>>data.");
>
>In the CGI:;Application docs it says to never print anything out
>only to return.. it there an exception when reporting errors ?
die circumvents the regular CGI::Application processing. CGI::Carp's
die handler takes whatever output is returned from the error
function, adds the necessary headers, returns it to the browser, and
then exits.
This is what I use at the top of my CGI::App class:
BEGIN
{
# Change the server admin address displayed in error messages
$ENV{SERVER_ADMIN} = "gregm\@"."alum.wpi.edu";
use CGI::Carp;
open(LOG, ">>my_log_file.txt") and CGI::Carp::carpout(LOG);
}
package my_package;
use base 'CGI::Application';
use CGI::Carp qw(fatalsToBrowser);
sub Error
{
my $msg = shift;
my $templ = $template;
if(defined $templ)
{
# Prevent errors in Template from recursing
$template = undef;
$templ->param(Message => $msg);
$templ->param(Error => $DBI::errstr);
print $templ->output();
}
else
{
print "<HTML><HEAD><TITLE>Database Error</TITLE></HEAD>";
print "<BODY><H1>Database Error</H1><P>$msg</P>";
print "<P>$DBI::errstr</P></BODY></HTML>";
}
}
sub setup
{
my $self = shift;
my $query = $self->query();
# Create the error page template
$template = $self->load_tmpl('DBError.html');
CGI::Carp::set_message(\&Error);
This makes die use a nicely formatted page that I provide through
HTML::Template, if possible. The only time this doesn't take effect is
when it doesn't get to the setup, such as a compile error.
--
Greg Marr
[EMAIL PROTECTED]
"We thought you were dead."
"I was, but I'm better now." - Sheridan, "The Summoning"
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]