- スクリプトの実行を停止しない例外と停止する例外はありますか?変換されたエラーを区別する方法がない場合はどうすればよいですか?
例外がキャッチされても、スクリプトの実行は停止しません。変換されたエラーを認識するには:
try {
// ...
} catch (ErrorException $e) {
// converted error (probably)
} catch (Exception $e) {
// another kind of exception; this basically catches all
}
または:
function handle_exception(Exception $e)
{
if ($e instanceof ErrorException) {
// converted error (probably)
} else {
// another kind of exception
}
}
set_exception_handler('handle_exception');
ErrorException
これはどのコードでもスローされる可能性がありますが、set_error_handler()
登録された関数でのみ通常のエラーを変換することを目的としていたことに注意してください。
- エラーを例外に変換するには、set_error_handler()を呼び出し、そこに新しいErrorException()をスローします...次は何ですか?set_exception_handler()は自動的に呼び出されますか?
ErrorException
エラーハンドラー関数からスローされたものがコード内の他の場所でキャッチされない場合、登録された例外ハンドラー(を使用して設定set_exception_handler()
)が呼び出されます。