set_exception_handler

(PHP 5)

set_exception_handler --  ユーザ定義の例外ハンドラ関数を設定する

説明

string set_exception_handler ( callback exception_handler )

例外がtry/catchブロックの中でキャッチされなかった場合の デフォルトの例外ハンドラを設定します。 例外は、exception_handler がコールされた後に 停止します。

exception_handler は、 set_exception_handler()をコールする前に 定義する必要があります。この関数は、パラメータを一つ とる必要があります。 このパラメータは、スローされた例外オブジェクトとなります。 exception_handler ( object exception )

exception

キャッチされない例外が発生した際にコールされる関数の名前

パラメータ

exception_handler

キャッチされない例外が発生した際にコールされる関数の名前

戻り値

前に定義された例外ハンドラまたはエラー発生時にFALSEを返します。 前にハンドラが定義されていない場合、空の文字列が返されます。

例 1. set_exception_handler() の例

<?php
function exception_handler($exception) {
  echo
"Uncaught exception: " , $exception->getMessage(), "\n";
}

set_exception_handler('exception_handler');

throw new Exception('Uncaught Exception');
echo
"Not Executed\n";
?>

以下も参照ください

restore_exception_handler() restore_error_handler() error_reporting() そして PHP 5例外