Yaf_Dispatcher::catchException
(Yaf >=1.0.0)
Yaf_Dispatcher::catchException — Switch on/off exception catching
Parameters
flag
-
Whether Yaf should catch uncaught exceptions and dispatch them to
ErrorController::error.
Note:
Since Yaf 2.2.0, if this parameter is not given, the current state
is returned instead.
Return Values
Returns the Yaf_Dispatcher object itself when
flag is given, or a bool indicating whether
exception catching is enabled when it is not.
Examples
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;
}
}
}
?>
The above example will output
something similar to:
/* 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