Zend framework automatically handles exceptions using the errorController. You can enable it by adding the following line in you config file.
resources.frontController.throwExceptions = 0
If you want to handle exceptions manually then, rather then writing try/catch block all over the code you can centralize it using the code below.
Tell Zend Framework to not handle exceptions. Do this in your application.ini
resources.frontController.throwExceptions = 1
Define a custom method to handle exceptions in your Bootstrap class.
public function __handleExceptions(Exception $e){
//render a view with a simple error message for the user
//and send an email with the error to admin
}
Override the _bootstrap() and run() methods of Zend_Application_Bootstrap_Bootstrap in your Bootstrap class as shown below. This will catch all the exceptions thrown during the bootstrapping and request dispatching process and call your custom exception handler.
protected function _bootstrap($resource = null)
{
try {
parent::_bootstrap($resource);
} catch(Exception $e) {
$this->__handleExecptions($e);
}
}
public function run()
{
try {
parent::run();
} catch(Exception $e) {
$this->__handleExecptions($e);
}
}
This will eliminate the need of writing try/catch block at multiple places. Hope this helps.