array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'yaf-dispatcher.throwexception.php', 1 => 'Yaf_Dispatcher::throwException', ), 'up' => array ( 0 => 'class.yaf-dispatcher.php', 1 => 'Yaf_Dispatcher', ), 'prev' => array ( 0 => 'yaf-dispatcher.setview.php', 1 => 'Yaf_Dispatcher::setView', ), 'next' => array ( 0 => 'class.yaf-config-abstract.php', 1 => 'Yaf_Config_Abstract', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/yaf/yaf_dispatcher/throwexception.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(Yaf >=1.0.0)
Yaf_Dispatcher::throwException — 开启/关闭异常抛出
当意外的错误发生的时候,开启/关闭异常抛出。当开启的时候,Yaf 将会抛出异常而不是触发可捕捉的错误。
你也可以使用 application.dispatcher.throwException 来达到相同的目的。
flag
bool
示例 #1 Yaf_Dispatcher::throwexception() 示例
<?php
$config = array(
'application' => array(
'directory' => dirname(__FILE__),
),
);
$app = new Yaf_Application($config);
$app->getDispatcher()->throwException(true);
try {
$app->run();
} catch (Yaf_Exception $e) {
var_dump($e->getMessage());
}
?>
以上示例的输出类似于:
string(59) "Could not find controller script /tmp/controllers/Index.php"
示例 #2 Yaf_Dispatcher::throwexception() 示例
<?php
$config = array(
'application' => array(
'directory' => dirname(__FILE__),
),
);
$app = new Yaf_Application($config);
$app->getDispatcher()->throwException(false);
$app->run();
?>
以上示例的输出类似于:
PHP Catchable fatal error: Yaf_Application::run(): Could not find controller script /tmp/controllers/Index.php in /tmp/1.php on line 12