Re: some questions about error handling
| From: | Justin Patrin | Date: | Tue, 04 Sep 2007 18:27:33 +0000 |
| Subject: | Re: some questions about error handling | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-27872@lists.php.net to get a copy of this message | ||
On 9/4/07, Luca Giandoso <luca.giandoso@gmail.com> wrote:
> I have to manage MDB2 errors in different ways, sometimes I have to
> log that errors and rollback and sometimes I have only to raise an
> error to make the caller function know what happened.
>
> How can I get the reference to the MDB2 object from the error handling
> function set with setErrorHandling()? I need a global MDB2 variable,
> and in this case is it safe to switch error handler?
> I have to extend MDB2 class with an error handler to have the
> reference of that object?
>
I assume you're using PEAR_ERROR_CALLBACK in setErrorHandling? This is
ok if you always want to do the same thing with your errors but if you
want to do things like sometimes rolling back or cleaning up then you
should be "catching" these errors in your code in the places where the
error happens.
$sth = $db->query($sql);
if (PEAR::isError($sth)) {
//rollback
}
--
Justin Patrin