Dutch PHP Conference 2027

Yaf_Dispatcher::catchException

(Yaf >=1.0.0)

Yaf_Dispatcher::catchExceptionSwitch on/off exception catching

Descrizione

public function Yaf_Dispatcher::catchException(?bool $flag = null): Yaf_Dispatcher|bool

While application.dispatcher.throwException is on (which can also be enabled by calling Yaf_Dispatcher::throwException()), Yaf throws exceptions when errors occur instead of triggering errors.

If exception catching is additionally enabled via this method (or via application.dispatcher.catchException), all uncaught exceptions are caught and dispatched to ErrorController::error, if one is defined.

Elenco dei parametri

flag

Whether Yaf should catch uncaught exceptions and dispatch them to ErrorController::error.

Nota:

Since Yaf 2.2.0, if this parameter is not given, the current state is returned instead.

Valori restituiti

Returns the Yaf_Dispatcher object itself when flag is given, or a bool indicating whether exception catching is enabled when it is not.

Esempi

Example #1 Yaf_Dispatcher::catchException() example

<?php
/* if you defined an ErrorController like following */
class ErrorController extends Yaf_Controller_Abstract {
     /**
      * you can also call Yaf_Request_Abstract::getException to get the
      * uncaught exception.
      */
     public function errorAction($exception) {
        /* an error occurred */
        switch ($exception->getCode()) {
            case YAF_ERR_NOTFOUND_MODULE:
            case YAF_ERR_NOTFOUND_CONTROLLER:
            case YAF_ERR_NOTFOUND_ACTION:
            case YAF_ERR_NOTFOUND_VIEW:
                echo 404, ":", $exception->getMessage();
                break;
            default :
                $message = $exception->getMessage();
                echo 0, ":", $exception->getMessage();
                break;
        }
     }
}
?>

Il precedente esempio visualizzerà qualcosa simile a:

/* now if some error occurs, assuming accessing a non-existent controller
   (or you can throw an exception yourself): */
404:Could not find controller script **/application/controllers/No-exists-controller.php

Vedere anche:

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top