I am stuck with PHP4 and I really miss exceptions. The more I think about it, the more I realize I just hate the way I've been doing error handling in all of my previous work - the code is just littered with redundant error checks. I decided to not do this in my next project.
The solution may seem obvious - set_error_handler() and trigger_error() whenever you need to. Since I really don't care about files, line numbers indicating where the error occured, I would prefer using my own class. The call could be something like this (to be used in any class):
The error handler could then pick a view to display the error.PHP Code:ErrorHandler::handle($error, $type); //$error - error ID
It may be ok when you have a website in a single language: you could pass the whole error message instead of ID to the handle() method. But I frequently need to add additional languages.
I could:
1. Instantiate ErrorHandler in a high level class (controller) with the right language params and pass the object around (that will probably make way too many passes).
3. Apply Observer pattern and make the objects that can produce errors act as observables (subjects).
Both seem to be too much for this kind of task. So far I haven't found a simple solution to this. Any ideas?
EDIT: This post is related to this one.





Bookmarks