-- Dinh <[EMAIL PROTECTED]> wrote (on Sunday, 17 December 2006, 09:08 PM +0700): > I wonder what is the proper way to catch Exception in bootstrap file. In my > code, I have done as follows: > > try > { > $controller = Zend_Controller_Front::getInstance(); > > $controller->throwExceptions(true); > $response = $controller->setControllerDirectory('./app/controllers') > ->setRequest($request) > ->setRouter($router) > ->setBaseUrl($baseUrl) > ->dispatch(); > > echo $response;
Btw, the same changeset that introduced throwExceptions() also made the front controller send response output by default, so it's no longer necessary to grab and echo the $response object. If you want the front controller not to render the response object and return it instead, use $controller->returnResponse(true). > } > catch (Zend_Controller_Dispatcher_Exception $ex) > { > $request = $controller->getRequest(); > echo "Exception: ".$request->getControllerName()."Controller class not > found. ".$request->getActionName()."Action() not found. "; > } > > > However, it only works with URL like this: http://domain/NotExistedController/ > notExistedActionForSure > > my try{} catch does not have any effect when user types: http://domain/ > ExistedController/notExistedAction . Exception can not be caught so it > displayed as follows: > > Zend_Controller_Exception: IndexController::doAction() does not exist and was > not trapped in __call() in D:\webroot\Zend_Framework\library\Zend.php on line > 229 Call Stack: 0.0095 1. {main}() D:\webroot\uproject\helloworld\index.php:0 > 0.2894 2. Zend_Controller_Front->dispatch() D:\webroot\uproject\helloworld\ > index.php:103 > > Is there anyway to catch this kind of exception? In your try/catch block above, you only catch Zend_Controller_Dispatcher_Exceptions. The second exception you display is a Zend_Controller_Exception. You should modify your try/catch block to add a second catch for these, or have the catch block catch a more generic type of exception: try { // ... } catch (Zend_Controller_Dispatcher_Exception $e) { // dispatcher exceptions } catch (Zend_Controller_Exception $e) { // controller exceptions } // you could do even more here... or: try { // ... } catch (Exception $e) { // handle any exception } -- Matthew Weier O'Phinney PHP Developer | [EMAIL PROTECTED] Zend - The PHP Company | http://www.zend.com/