PHP set_exception_handler()関数
例
ユーザー定義の例外ハンドラー関数を設定します。
<?php
// A user-defined exception handler function
function myException($exception)
{
echo "<b>Exception:</b> ", $exception->getMessage();
}
// Set user-defined exception handler function
set_exception_handler("myException");
// Throw exception
throw new Exception("Uncaught exception occurred!");
?>
定義と使用法
set_exception_handler()関数は、ユーザー定義の例外ハンドラー関数を設定します。
例外ハンドラが呼び出されると、スクリプトの実行が停止します。
構文
set_exception_handler(exceptionhandler);
パラメータ値
Parameter | Description |
---|---|
exceptionhandler | Required. Specifies the name of the function to be run when an uncaught exception occurs. NULL can be passed instead, to reset this handler to its default state |
技術的な詳細
戻り値: | 以前に定義された例外ハンドラーを含む文字列、またはエラーの場合、または以前のハンドラーが定義されていない場合はNULL |
---|---|
PHPバージョン: | 5.0以降 |
PHP変更ログ: | 以前は、NULLが渡された場合、この関数はTRUEを返しました。PHP5.5以降の以前のハンドラーを返します |
PHPエラーリファレンス