Error Handling in PHP
PHP provides built-in functions to handle errors and exceptions. These functions can be used to catch and handle errors, and to log error messages.
Example:
php
// set error handler function
function custom_error_handler($errno, $errstr, $errfile, $errline) {
echo "<b>Error:</b> [$errno] $errstr<br>";
echo "Error on line $errline in $errfile<br>";
error_log("Error: [$errno] $errstr on line $errline in $errfile", 1, "admin@example.com");
}
set_error_handler("custom_error_handler");
// trigger an error
echo $test;
No comments:
Post a Comment