Answer the question
In order to leave comments, you need to log in
Why doesn't error trapping work?
Here is an example that causes the script to crash instead of handling the error.
<?php
error_reporting(E_ERROR);
echo "Начало\n";
try {
$a->foo(); # Переменной $a не существует!
} catch (Exception $e) {
echo "Произошла ошибка: " . $e->getMessage() . "\n";
}
echo "Конец\n";
Start
PHP Fatal error: Call to a member function foo() on a non-object in /home/user/www/test/try.php on line 8
Answer the question
In order to leave comments, you need to log in
This works in PHP 7.
For lower versions, you need to use error_handler(), but for Fatal, it may not work, so solutions like register_shutdown_function() are sometimes used.
Read https://habrahabr.ru/post/261451/
An exception is not an error. But catching and handling (without crashing) a level error E_ERROR
as an exception is possible only from PHP 7 version.
Error
Throwable
Throwable exception and errors in php7
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question