in reply to Howto fetch procedure return value
You may want to also look in the DBI manual about setting RaiseError => 1 on your database handle. This allows errors to throw exceptions and saves a lot of 'or die' coding.
eval { $sth->execute(); #fetch rows here }; if($@) # if anything bad happened { print STDERR "My clever message here: $@"; # or even #die "Message"; }
Now if DBI enounters any serious error with the connection etc., it will call die and the eval will catch it and set $@ and then reading $@ allows your script to handle the error which might be as simple as calling die in the if block. But this way you only need 1 die and you cannot forget to check for errors on your DBI interactions since every interaction done on that handle gets error checked automatically.
Beware that if you use that handle outside an eval and there is an error, die is called which will end the script (which may very well be the desired behaviour).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Howto fetch procedure return value
by aquarium (Curate) on Apr 04, 2003 at 10:57 UTC |