Page 2 of 2

Re: Exceptions and logging

Posted: Sun Aug 30, 2009 7:10 am
by m4rw3r
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();

Re: Exceptions and logging

Posted: Sun Aug 30, 2009 7:17 am
by Eran
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.

Re: Exceptions and logging

Posted: Sun Aug 30, 2009 7:31 am
by m4rw3r
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.

Re: Exceptions and logging

Posted: Sun Aug 30, 2009 7:40 am
by Eran
Yes, sounds like a good way to handle it.

Re: Exceptions and logging

Posted: Sun Aug 30, 2009 9:05 am
by Ollie Saunders
BTW you should ignore what I said, I hadn't read the thread properly.
Leave logging to your library users.