Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to throw exceptions for perl cgi program?
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


Report this thread to moderator Post Follow-up to this message
Old Post
Siegfried Heintze
12-28-04 08:56 PM


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);" 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/

Report this thread to moderator Post Follow-up to this message
Old Post
Peter Scott
12-29-04 01:55 PM


RE: How to throw exceptions for perl cgi program?
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>




Report this thread to moderator Post Follow-up to this message
Old Post
Siegfried Heintze
01-01-05 01:55 AM


Re: How to throw exceptions for perl cgi program?

Siegfried 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.

Report this thread to moderator Post Follow-up to this message
Old Post
JupiterHost.Net
01-01-05 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:29 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.