On Fri, Nov 18, 2005 at 03:49:21PM +0200, Nitzan Shaked wrote:
> Thanks Tim.
>
> > I'll clarify the docs. Basically all methods calls reset err except for
> > just a few special cases such as err and errstr, obviously, and FETCH
> > eg $foo = $h->{SomeAttribute}).
>
> From the first part of your answer I understand that's it's always okay to
> test for "defined DBI::err" (if I want to die on warnings) or "DBI::err" if
> I am willing to live with warnings and would like to die on errors only. Is
> that correct?
You've missed out the $ sigils, but other than that, yes.
As per the docs:
A driver may return C<0> from err() to indicate a warning condition
after a method call. Similarly, a driver may return an empty string
to indicate a 'success with information' condition. In both these
cases the value is false but not undef. The errstr() and state()
methods may be used to retrieve extra information in these cases.
> > Well, if you're going to die() I'd just set RaiseError and forget about it.
> > If there's some good reason you don't want to use RaiseError then this
> > would do:
>
> Of course when I write "die" I don't really mean die, I have error handling
> code which does quite a bit. It's just a shorthand for writing. Otherwise I
> would use RaiseError as you suggest.
Okay. (Don't forget to check out the HandleError attribute.)
> > my $hr = $dbh->selectrow_hashref( ... ) or die(...);
>
> ... but from your first part of your answer I may also do:
> my $hr = $dbh->selectrow_hashref( ... );
> defined $DBI::err and do_special_error_handling_code();
Yes.
Tim.