Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This code demonstrates how to setup your application
- * to intelligently handle errors of all types.
- */
- ini_set('display_errors', 'Off');
- error_reporting(0);
- /**
- * Do something useful like log the error and send back a response.
- * This is the global application error handler.
- */
- function handleErrors()
- {
- echo 'something bad happened';
- exit;
- }
- /**
- * This captures all uncaught exceptions.
- */
- set_exception_handler('handleErrors');
- /**
- * Capture vanilla PHP errors and just convert them to exceptions
- */
- set_error_handler('handleErrors');
- /**
- * The following is required to actually handle E_ERROR type errors
- */
- register_shutdown_function(function () {
- $error = error_get_last();
- if (!is_null($error)) {
- handleErrors();
- }
- });
- // ======================================================================================================
- /**
- * Application code examples
- */
- // this should just hit the set_exception_handler() handler directly.
- throw new Exception;
- /**
- * This will cause an E_DEPRECATED to be raised. Sent to set_error_handler()
- */
- ereg();
- /**
- * This will cause an E_ERROR to be raised. For some reason PHP's set_error_handler()
- * won't handle these. Rather you register a register_shutdown_function()
- * and get the last error, if one exists then handle the error.
- */
- some_fake_function_name();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement