Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
Moderator: General Moderators
m4rw3r
Forum Commoner
Posts: 33 Joined: Mon Aug 03, 2009 4:19 pm
Location: Sweden
Post
by m4rw3r » Sun Aug 30, 2009 7:10 am
So I should use exceptions completely? or should I make some kind of level on the exceptions to throw?
Like this?
Code: Select all
if(Db::getErrorLevel() & Db::WARNING)
throw new Exception();
Eran
DevNet Master
Posts: 3549 Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME
Post
by Eran » Sun Aug 30, 2009 7:17 am
I would handle it by abstracting error handling to a dedicated method / component. That component could, based on configuration, throw an exception or return formatted errors. Then direct all your error handling to that method/component.
m4rw3r
Forum Commoner
Posts: 33 Joined: Mon Aug 03, 2009 4:19 pm
Location: Sweden
Post
by m4rw3r » Sun Aug 30, 2009 7:31 am
Currently I have several different exception classes, to make it easy to filter them.
So would this be a good solution?
Code: Select all
Db::handleError(new Db_Exception_InvalidConfig($name));
And the handleError() method would then throw the error if the user has configured it to do that, otherwise it will add it to a stack or whatever.
Eran
DevNet Master
Posts: 3549 Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME
Post
by Eran » Sun Aug 30, 2009 7:40 am
Yes, sounds like a good way to handle it.
Ollie Saunders
DevNet Master
Posts: 3179 Joined: Tue May 24, 2005 6:01 pm
Location: UK
Post
by Ollie Saunders » Sun Aug 30, 2009 9:05 am
BTW you should ignore what I said, I hadn't read the thread properly.
Leave logging to your library users.