For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > December 2004 > How to throw exceptions for perl cgi program?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to throw exceptions for perl cgi program?
Siegfried Heintze

2004-12-28, 3:56 pm

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

Peter Scott

2004-12-29, 8:55 am

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/
Siegfried Heintze

2004-12-31, 8:55 pm

How 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>



JupiterHost.Net

2004-12-31, 8:55 pm



Siegfried Heintze wrote:

> How do I throw an exception when my database API reports an error code? The
> 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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com