I have a service layer which is responsible for handling exceptions.
The question is, should I be handling exceptions in the service layer and how can I pass an appropriate exception message to a view?
class App_Service_Feed {
function create() {
//...
try {
$feed->getMapper->insert();
} catch (Zend_Db_Statement_Exception $e) {
//what do I return here?
} catch (Exception $e) {
//what do I return here?
}
}
}
I’m thinking of returning a response object of some description, so that in my controller I manipulate this.
class App_Controller {
//...
$response = $service->create();
if($response->status) {
}
}
Alternatively, I’m wondering whether to handle exceptions in the controller…
Even better than the way of jason bourne (yeah):
Why is this better?
The best way to implement Exceptions is to have a hierarchy of extending Exception classes.
So every folder contains an Exception.php. This way you can catch and rethrow Exceptions on every level, if necessary.