RE: [PEAR-DEV] Some more PHP5-related ruminations: Exceptions
| From: | Hans Lellelid | Date: | Sat, 05 Apr 2003 18:10:14 +0000 |
| Subject: | RE: [PEAR-DEV] Some more PHP5-related ruminations: Exceptions | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-14925@lists.php.net to get a copy of this message | ||
> The execptions in PHP5 look nice, and should make some of the
> error handling simpler and more consistent.
>
> One thing that the Exception class does not have is the
> ability to chain them. Tried subclassing it but did not work
> too well (the filename and line were always wrong),
The reason the FILE & LINE were wrong is that they are set by PHP5's
Exception constructor ... So if Exception::Exception() is called by your
subclass, the file & line will be set from the subclass' constructor.
To avoid this just don't override the exception constructor. Use things
like setCode(), setDebugInfo() instead of expanding the constructor
signature.
So, this will work:
$exc = new SQLException(); // File & line set from this point
$exc->setNativeError(mysql_error());
throw $exc;
Cheers,
Hans
Attachment: [application/x-pkcs7-signature] smime.p7s
Attachment: [application/x-pkcs7-signature] smime.p7s