php8.5
Home/ Manual/ yaf / yaf_dispatcher/ Yaf_Dispatcher::throwException

Yaf_Dispatcher::throwException

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Switch on/off exception throwing

Description

Yaf_Dispatcher::throwException(bool|null $flag = null): Yaf_Dispatcher|bool

Switch on/off exception throwing when an unexpected error occurs. When this is on, Yaf throws exceptions instead of triggering catchable errors.

You can also use application.dispatcher.throwException to achieve the same purpose.

Parameters

flag

Whether Yaf should throw exceptions on errors.

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 Boolean indicating whether exception throwing is enabled when it is not.

Examples

Yaf_Dispatcher::throwException() example

php
<?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());
}
?>

The above example will output something similar to:

output
string(59) "Could not find controller script /tmp/controllers/Index.php"

Yaf_Dispatcher::throwException() example

php
<?php
$config = array(
    'application' => array(
        'directory' => dirname(__FILE__),
    ),
);
$app = new Yaf_Application($config);

$app->getDispatcher()->throwException(false);

$app->run();
?>

The above example will output something similar to:

output
PHP Catchable fatal error:  Yaf_Application::run(): Could not find controller script /tmp/controllers/Index.php in /tmp/1.php on line 12

See Also

  • Yaf_Dispatcher::catchException
  • Yaf_Exception

Source: reference/yaf/yaf_dispatcher/throwexception.xml · from the official PHP manual (php/doc-en)