bonjour,
je souhaiterais mettre en place une gestion des erreurs sur mon applis.
j'ai mis un controller Error comme dans la doc en ajoutant un certain nombre de cas :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
 
/**
 * Error controller
 *
 * @uses       Zend_Controller_Action
 * @package    QuickStart
 * @subpackage Controller
 */
class ErrorController extends Zend_Controller_Action
{
    /**
     * errorAction() is the action that will be called by the "ErrorHandler" 
     * plugin.  When an error/exception has been encountered
     * in a ZF MVC application (assuming the ErrorHandler has not been disabled
     * in your bootstrap) - the Errorhandler will set the next dispatchable 
     * action to come here.  This is the "default" module, "error" controller, 
     * specifically, the "error" action.  These options are configurable, see 
     * {@link http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standar
     *
     * @return void
     */
    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');
        switch ($errors->type) { 
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->message = 'Page not found';
                break;
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER:
                switch (get_class($this->_exception->exception)) {
                    case 'Zend_View_Exception' :
                        $this->getResponse()->setHttpResponseCode(500);
                        $this->view->message = 'Erreur de traitement d\'une vue';
                        break;
                    case 'Zend_Db_Exception' :
                        $this->getResponse()->setHttpResponseCode(503);
                        $this->view->message = 'Erreur de traitement dans la base de données';
                        break;
                    case 'Metier_Exception' :
                        $this->getResponse()->setHttpResponseCode(200);
                        $this->view->message = $this->_exception->exception->getMessage();
                        break;
                    default:
                        $this->getResponse()->setHttpResponseCode(500);
                        $this->view->message = 'Erreur inconnue : '. $this->_exception->exception->getMessage();
                        break;
                }
            break;
 
            default:
                // application error 
                $this->getResponse()->setHttpResponseCode(500);
                $this->view->message = 'Application error';
                break;
        }
 
        $this->view->exception = $errors->exception;
        $this->view->request   = $errors->request;
    }
 
}
ça marche pour les erreur NO_CONTROLLER et NO_ACTION, par contre je sais pas comment faire pour tomber dans le cas EXCEPTION_OTHER !

par exemple dans mon BootStrap, j'ai fais :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
protected function _initDb(array $options = array())
    {
        $this->bootstrap('config');
        $config = $this->getResource('config');
        $db = Zend_Db::factory($config->resources->db);
        try
        {
            $db->getConnection();
        }
        catch(Zend_Db_Adapter_Exception $e)
        {
            die($e->getMessage());
        }
 
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
        Zend_Registry::set( 'dbAdapter', $db );
        return $db;
    }
mais à la place de faire un die(), j'aimerais bien pouvoir tombé sur mon controller error dans le cas 'Zend_Db_Exception';