エラーと例外の中心的なエラー処理関数としてErrorExceptionを使用しています。
例:
set_error_handler('my_error_handler');
set_exception_handler('my_exception_handler');
function my_error_handler ($errno, $errstr, $errfile, $errline)
{
my_exception_handler(new ErrorException($errstr, 0, $errno, $errfile, $errline));
}
function my_exception_handler ($e)
{
echo $e->getSeverity();
echo $e->getCode();
echo $e->getMessage();
}
現在は、デフォルト$e->getSeverity();
にのみ存在しErrorException
、デフォルトには存在しないように見えますException
。
throw new Exception('test');
私が得るときFatal error: Call to undefined method Exception::getSeverity()
。
しかし、私throw new ErrorException('test');
が期待どおりに機能するとき。
これは論理的に思えますがthrow new Exception('test');
、致命的なエラーが発生せずに使用できる方法はありますか?ほとんどのサードパーティライブラリは(ErrorExceptionではなく)例外を使用するため、サードパーティの例外が発生すると問題が発生し、致命的なエラーが発生します。どうすればこれを解決できますか?