Try {code...} catch (Exception $ e) {code...} No content in the log after execution. Why? What types of errors can trycatch capture? Try {
$a = 1/0;
} Catch (Exception $ e ){
file_put_contents("filelog.log", $e.getMessage(), FILE_APPEND);
}
No log content after execution. Why? What types of errors can be captured by try catch?
Reply content:
Try {
$a = 1/0;
} Catch (Exception $ e ){
file_put_contents("filelog.log", $e.getMessage(), FILE_APPEND);
}
No log content after execution. Why? What types of errors can be captured by try catch?
try {} catch {}YesPHP 5The later mechanism is added because the switchover from the original error mechanism still requires a transitional period.PHP 5These two error mechanisms coexist throughout the lifecycle, and most of the core errors remainErrorFormat. However, errors in most extensions have gradually changedThrowThrow andPHP 7There are also many core errorsThrowThrow, but completely switchesThrowBefore the mechanism, it is best to handle the coexistence of the two mechanisms.
Division by zero this is warning not Exception.
Use set_error_handler to capture
set_error_handler(function($errno, $errstr) { var_dump($errstr);});$a = 1/0;
It is not recommended to capture such exceptions. You just need to consider it carefully when writing the program.
Determine whether the divisor is null and 0 before execution.
Mysql can also run 1/0! The result is null.