1. Go to this page and download the library: Download weew/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/ */
weew / error-handler example snippets
$errorHandler = new ErrorHandler();
// enable exception handling
$errorHandler->enableExceptionHandling();
// enable handling of recoverable php errors
$errorHandler->enableRecoverableErrorHandling();
// enable handling of fatal php errors
$errorHandler->enableFatalErrorHandling();
// enable handling of recoverable and fatal php errors
$errorHandler->enableErrorHandling();
// enable handling of exceptions, recoverable and fatal php errors
$errorHandler->enable();
// is this kind of error recoverable or not
$error->isRecoverable();
// get error type (E_WARNING, E_STRICT, etc.)
$error->getCode();
// get error message
$error->getMessage();
// get error file
$error->getFile();
// get error line
$error->getLine();
$errorHandler = new ErrorHandler();
$errorHandler->addRecoverableErrorHandler(function(IError $error) {
return true;
});
$errorHandler = new ErrorHandler();
$errorHandler->addFatalErrorHandler(function(IError $error) {
return true;
});
$errorHandler = new ErrorHandler();
$errorHandler->addErrorHandler(function(IError $error) {
if ($error->isRecoverable()) {
return true;
}
});
class CustomErrorHandler implements INativeErrorHandler {
public function handle(IError $error) {
return true;
}
}
$errorHandler = new ErrorHandler();
$errorHandler->addErrorHandler(new CustomErrorHandler());
$errorHandler = new ErrorHandler();
$errorHandler->addExceptionHandler(function(HttpException $ex) {
return true;
});
class CustomExceptionHandler implements IExceptionHandler {
public function supports(Exception $ex) {
return $ex instanceof HttpException;
}
public function handle(HttpException $ex) {
return true;
}
}
$errorHandler = new ErrorHandler();
$errorHandler->addExceptionHandler(new CustomExceptionHandler());
$errorHandler = new ErrorHandler();
$errorHandler->convertErrorsToExceptions();
$errorHandler->enableExceptionHandling();
// or
$errorHandler = new ErrorHandler(true);
$errorHandler->enableExceptionHandling();
$errorHandler->addExceptionHandler(function(IErrorException $ex) {
// all kinds of php errors (E_WARNING, E_STRICT, etc.) can now be handled
// here in form of an exception
return true;
});
// get numeric representation of the error type (E_WARNING, E_STRICT, etc.)
$ex->getErrorCode();
// get error message
$ex->getErrorMessage();
// get error file
$ex->getErrorFile();
// get error line
$ex->getErrorLine();
// check wether the error was recoverable or not
$ex->isRecoverable();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.