Yaf_Dispatcher::catchException

(Yaf >=1.0.0)

Yaf_Dispatcher::catchExceptionSwitch on/off exception catching

Açıklama

public Yaf_Dispatcher::catchException(bool $flag = ?): Yaf_Dispatcher

While the application.dispatcher.throwException is On(you can also calling to Yaf_Dispatcher::throwException(TRUE)() to enable it), Yaf will throw Exception when error occurs instead of trigger error.

then if you enable Yaf_Dispatcher::catchException()(also can enabled by set application.dispatcher.catchException), all uncaught Exceptions will be caught by ErrorController::error if you have defined one.

Bağımsız Değişkenler

flag

bool

Dönen Değerler

Örnekler

Örnek 1 Yaf_Dispatcher::catchException() example

/* if you defined a ErrorController like following */
<?php
class ErrorController extends Yaf_Controller_Abstract {
/**
* you can also call to Yaf_Request_Abstract::getException to get the
* un-caught exception.
*/
public function errorAction($exception) {
/* error occurs */
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;
}
}
}
?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

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

Ayrıca Bakınız

add a note add a note

User Contributed Notes

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