Re: [PEPr] -1 for RFC::Error Handling Guidelines for
| From: | Greg Beaver | Date: | Mon, 30 Aug 2004 19:13:02 +0000 |
| Subject: | Re: [PEPr] -1 for RFC::Error Handling Guidelines for | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-33084@lists.php.net to get a copy of this message | ||
Hans L wrote:
I think that everyone (esp Greg) has acknowledged that to be designed for warnings, PEAR_ErrorStack would need some [perhaps minor] modifications. I remember, in particular, the suggestion that the stackActually, it works fine as it is. Some people are uncomfortable with the name, but that has no effect on the functionality. Currently, promoting a warning to an exception involves something like this code (Exception can be any exception classname): <?php $a = $stack->getErrors(); $e = new Exception($a[0]['message'], $a[0]['code']); $e->userinfo = $a[0]; // if the exception class doesn't provide a way to pass this info in directly throw $e; ?> I was only going to take those three lines and make them into a convenience method. Converting an exception into a warning is even easier <?php } catch ($e) {
$stack->push($e->getCode(), 'warning', array(), $e->getMessage(), $e, $e->getTrace());} This one-liner can obviously be incorporated into a method named demoteException() which would take an exception and a level ('warning'/'notice') However, all of these changes are simply conveniences. It works fine as it is. I actually think more attention needs to be given to PEAR_Exception at this point, to figure out if there is a better way to do warning promotion. In addition, at least providing the option to add more information than simply an error message and code is a priority for me (although Alan doesn't want that in the base class). Again, none of these *words* need be argued over right now, it's better to *code* solutions first in this case and try them out. Greg