Code Comments
Programming Forum and web based access to our favorite programming groups.I'm buffering my html/javascript output in a large array of strings. This frees me to perform my computations independently of the order they appear in the output. However, I have a problem: Let us suppose I have an error from my database and I have not executed "print $q->header( ),start_html(-title => $case_name);"; yet. Is there a way I can throw an exception in my function (that retrieves data from the database) and let the main program have an exception handler that will execute "print $q->header( ),start_html(-title => $case_name);" earlier than normal so I can print my error messages and abort? Thanks, Siegfried
Post Follow-up to this messageIn article <200412281021484.SM01228@fasolt>,
siegfried@heintze.com (Siegfried Heintze) writes:
>I'm buffering my html/javascript output in a large array of strings. This
>frees me to perform my computations independently of the order they appear
>in the output.
>
>However, I have a problem: Let us suppose I have an error from my database
>and I have not executed "print $q->header( ),start_html(-title =>
>$case_name);"; yet.
>
>Is there a way I can throw an exception in my function (that retrieves data
>from the database) and let the main program have an exception handler that
>will execute "print $q->header( ),start_html(-title => $case_name);" earlie
r
>than normal so I can print my error messages and abort?
Main program:
eval {
# Save output in $page
};
if ($@) {
print $q->header, start_html(-title => 'Error'),
p("Error: $@");
}
else {
print $q->header, start_html(-title => $case_name);
print $page;
}
--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/
Post Follow-up to this messageHow do I throw an exception when my database API reports an error code? The
database implementation does not throw exceptions so I have to.
Thanks again!
Siegfried
-----Original Message-----
From: Peter Scott [mailto:peter@psdt.com]
Sent: Wednesday, December 29, 2004 4:19 AM
To: beginners@perl.org
Subject: Re: How to throw exceptions for perl cgi program?
In article <200412281021484.SM01228@fasolt>,
siegfried@heintze.com (Siegfried Heintze) writes:
>I'm buffering my html/javascript output in a large array of strings. This
>frees me to perform my computations independently of the order they appear
>in the output.
>
>However, I have a problem: Let us suppose I have an error from my database
>and I have not executed "print $q->header( ),start_html(-title =>
>$case_name);"; yet.
>
>Is there a way I can throw an exception in my function (that retrieves data
>from the database) and let the main program have an exception handler that
>will execute "print $q->header( ),start_html(-title => $case_name);"
earlier
>than normal so I can print my error messages and abort?
Main program:
eval {
# Save output in $page
};
if ($@) {
print $q->header, start_html(-title => 'Error'),
p("Error: $@");
}
else {
print $q->header, start_html(-title => $case_name);
print $page;
}
--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Post Follow-up to this messageSiegfried Heintze wrote: > How do I throw an exception when my database API reports an error code? Th e > database implementation does not throw exceptions so I have to. use the die() function... perldoc -f die $dbh->whatever($query) or die $dbh->errstr; Your specific API would have more info on specifically how to do it for that. You may also be able to use the Raise_Error (or something like that) option when creating a new $dbh onject. without more specific info about the how the dbh is created or used its difficult to be precise.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.