-- Jurian Sluiman <[email protected]> wrote (on Tuesday, 14 June 2011, 07:04 PM +0200): > Just a small brainstorm question: what type of exception do you use in > service > classes? In controllers, I use often the Zend_Controller_Action_Exception, > which can throw a 404 or 500 http error. At other places, other exceptions > are > more in place (eg a Zend_Auth_Exceptions for a 403 and "login required" > dialog). > > But, a service class (eg a Blog_Service_Article which fetches articles from > different categories for the blog module): what should it throw? In ZF1, SPL > exceptions are not used often. Zend_Service_Exception seems not the right one > either. > > So: what do you use?
I often create custom exception types (sometimes extending SPL exceptions) for specific types of functionality I want to capture and handle in the ErrorController. I then add case statements into that controller's exception type switch to allow specifying alternate headers and/or view scripts. As an example, a failed ACL check usually has me throwing an "UnauthorizedActionException". In my ErrorController, I then add a case for this, and return a 401 HTTP response header, and specify a custom view script indicating that they are unauthorized. -- Matthew Weier O'Phinney Project Lead | [email protected] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc -- List: [email protected] Info: http://framework.zend.com/archives Unsubscribe: [email protected]
