1. Go to this page and download the library: Download rammewerk/error-handler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rammewerk / error-handler example snippets
use Rammewerk\Component\ErrorHandler;
$errorHandling = new ErrorHandler();
$errorHandling->log( static function (\Throwable $e) {
# Log your exceptions
});
$errorHandling->report( static function (\Throwable $e) {
# Show the exception to your user.
});
use Rammewerk\Component\ErrorHandler;
CONST DEBUG_MODE = true;
$errorHandler = new ErrorHandler();
/** Log latest exception to JSON file */
$errorHandler->log( static function (\Throwable $e) {
file_put_contents( 'latest_error.json', json_encode($e->getMessage()) );
});
/** Show default 500 error page */
$errorHandler->report( static function () {
http_response_code( 500 );
echo file_get_contents( "errors/500.html" );
die;
} );
/**
* Show error details if DEBUG_MODE.
* Second argument here (true) is used to reset the report list.
* report closures
*/
if( DEBUG_MODE ) {
$errorHandler->report( function (\Throwable $e) {
$debug = new \CustomDebugClass();
$debug->exception($e);
die;
}, true);
}
$errorHandling->report( function (\Throwable $e) {
if( $e instanceof \MyCustomException) ) {
die('MyCustomException was thrown');
}
} );
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.