try{ //Your code here }catch(Throwable $e) { echo 'Error: '.$e; }// The set_error_handler() function sets a user-defined error handler function. // Note: The standard PHP error handler is completely bypassed if this function is used, and the user-defined error handler must terminate the script, die(), if necessary. // Note: If errors occur before the script is executed the custom error handler cannot be used since it is not registered at that time. <?php // A user-defined error handler function function myErrorHandler($errno, $errstr, $errfile, $errline) { echo "<b>Custom error:</b> [$errno] $errstr<br>"; echo " Error on line $errline in $errfile<br>"; } // Set user-defined error handler function set_error_handler("myErrorHandler"); $test=2; // Trigger error if ($test>1) { trigger_error("A custom error has been triggered"); } ?>