1. Go to this page and download the library: Download codemonster-ru/errors 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/ */
codemonster-ru / errors example snippets
use Codemonster\Errors\Handlers\SmartExceptionHandler;
_handler(function (Throwable $e) use ($handler) {
$response = $handler->handle($e);
if (php_sapi_name() !== 'cli') {
http_response_code($response->getStatusCode());
echo (string) $response;
} else {
fwrite(STDERR, (string) $response . PHP_EOL);
}
});
throw new RuntimeException('Something went wrong!');
use Codemonster\Errors\Handlers\SmartExceptionHandler;
use Codemonster\View\View;
$view = new View(...);
$viewRenderer = fn(string $template, array $data) => $view->render($template, $data);
$handler = new SmartExceptionHandler($viewRenderer, debug: true);
try {
throw new RuntimeException('Demo error');
} catch (Throwable $e) {
$response = $handler->handle($e);
echo $response;
}