Yaf_Dispatcher::catchException
(Yaf >=1.0.0)
Yaf_Dispatcher::catchException — 例外のキャッチのオン/オフを切り替える
説明
public Yaf_Dispatcher::catchException
([ bool $flag
] ) : Yaf_Dispatcher
application.dispatcher.throwException が On (あるいは Yaf_Dispatcher::throwException(TRUE)() で有効にした) 他愛、Yaf でエラーが発生したときに例外をスローします。
そのとき、Yaf_Dispatcher::catchException() を有効にする (あるいは application.dispatcher.catchException で有効にする) と、 もし ErrorController::error を定義していれば キャッチしなかった例外はすべて ErrorController::error に送られます。
パラメータ
flag
- bool
返り値
例
例1 Yaf_Dispatcher::catchException() の例
/* 次のような ErrorController を定義しているものとします */<?phpclass ErrorController extends Yaf_Controller_Abstract { /** * Yaf_Request_Abstract::getException を呼んで * 未処理の例外を取得します */ public function errorAction($exception) { /* エラーが発生した */ 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; } } }?>
上の例の出力は、 たとえば以下のようになります。
/* 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
参考
- Yaf_Dispatcher::throwException() - 例外のスローのオン/オフを切り替える
- Yaf_Dispatcher::setErrorHandler() - エラーハンドラを設定する