Re: Error-handling Question

From: Michael A Chase (mchase_at_ix.netcom.com)
Date: 12/15/03


Date: Mon, 15 Dec 2003 14:21:44 -0800 (PST)
To: paul.boutros@utoronto.ca, dbi-users@perl.org

On Mon, 15 Dec 2003 12:57:32 -0500 paul.boutros@utoronto.ca wrote:

> If I'm handling errors with eval {} if ($@) {} constructs, is there any
> hidden gotcha to grouping several statements in a single eval if I want
> any errors handled identically? For instance, can I wrap an execute
> and its fetches into one eval, as below, or is this something I should
> be wary of?

> if ($@) {
> $dbh->rollback();
> close(OUT);
> print "Error retrieving data\n";
> exit();
> }

It would be useful to know what went wrong. You should either include $@
in the print(), or capture $DBI::errstr before calling rollback() and
print that.

-- 
Mac :})
** I usually forward private questions to the appropriate mail list. **
Ask Smarter: http://www.catb.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.


Relevant Pages

  • Re: How to test status of handler sth?
    ... > if is not consistent when connection or something goes bad. ... After execute() a SELECT statement will leave $sth->true ... >> Give a hobbit a ring and he eats fish for an age. ...
    (perl.dbi.users)
  • Re: UNSUBSCRIBING
    ... Eventually the list admin ... I think it's been three months since the last such request. ... Give a hobbit a ring and he eats fish for an age. ...
    (perl.dbi.users)
  • Re: DBD-Oracle question for Win2000
    ... provides pre-compiled packages to install using PPM. ... Give a hobbit a ring and he eats fish for an age. ...
    (perl.dbi.users)
  • Re: Nested query problem
    ... > efficient to write the WHERE clause conditions as most restricting ... > restrictive conditions first in the WHERE - is that right? ... Give a hobbit a ring and he eats fish for an age. ...
    (perl.dbi.users)
  • Re: How to test status of handler sth?
    ... > either failing or I lost the handle (sth). ... Give a hobbit a ring and he eats fish for an age. ...
    (perl.dbi.users)