Forum und email

set_exception_handler

(PHP 5)

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

説明

string set_exception_handler ( callback $exception_handler )

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

パラメータ

exception_handler

キャッチされない例外が発生した際にコールされる関数の名前。 この関数は、set_exception_handler() をコールする前に定義する必要があります。 このハンドラ関数は、パラメータをひとつとる必要があります。 このパラメータは、スローされた例外オブジェクトとなります。

返り値

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

Example#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";
?>