Re: Error gettig automatically raised ?
| From: | Markus Fischer | Date: | Thu, 23 Aug 2001 14:05:07 +0000 |
| Subject: | Re: Error gettig automatically raised ? | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-285@lists.php.net to get a copy of this message | ||
On Thu, Aug 23, 2001 at 03:19:53PM +0200, Stig Sæther Bakken wrote :
> [Markus Fischer <mfischer@guru.josefine.at>]
> > Hi,
> >
> > When I define PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, ..) how
> > can I make this callback automatically called when an error
> > occurs ?
> >
> > e.g, my class does
> >
> > class foo extends PEAR {
> >
> > function foo() {
> >
> > $this->PEAR();
> >
> > PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$this,'method'));
> >
> > // that is fine
> > if ($some_test)
> > $this->raiseError('foobar corrupted', PEAR_ERROR_CALLBACK);
> >
> > $this->_db = DB::connect( long dsn ...
> >
> > // now shouldn't the connect automatically raise an error
> > // ?
> > [..snipped...]
> >
> > I use PEAR::setError and not $this->setError because I want all
> > errors be handled by this class...
>
> Setting the global error handler in a class constructor seems weird to
> me, I wouldn't design my code that way.
Ah, I see; this makes sense. Anyway, I won't need the _db anytime
when instancing the class so the move is good idea anyway ..
> In general, you should avoid
> doing stuff that can result in PEAR errors from a constructor, because
> you have no way of giving the error object back to the caller.
But when moving out everything out of the constructor and using
PEAR::setErrorHandling() it should be fine, no ?
> I assume the reason you want to set the global handler is that you
> want your _db object to use the same error handler as well?
Correct. In fact, I want _every_ possible PEAR error happen to
catch with this object.
> I've had
> the same problem myself, and I'm trying to think of a way to let
> aggregate objects "inherit" error reporting parameters.
>
> I'll drink to exceptions anytime. :-)
:))
- Markus