Set of the base exceptions
![Code Coverage][ico-scrutinizer]
![GitHub issues][ico-issues], (*1)
![PHP Version][ico-php-version], (*2)
This repository contains a set of useful exception classes., (*3)
The exception classes interface is extended with array of context data,
because often the message and the code are not enough to debug., (*4)
Install
Using Composer:, (*5)
composer require zeeproject/exceptions
Usage
Throw exceptions as usual, but you are able also to add context values:, (*6)
throw new InvalidArgumentException('Something went wrong', [
'key' => 'value',
]);
Now you can handle this exception, e.q. your error handler may log error details:, (*7)
final class ErrorHandler
{
private $logger;
public function __construct(Psr\Log\LoggerInterface $logger)
{
$this->logger = $logger;
}
public function handleException(Exception $exception)
{
if ($exception instanceof Zee\Exceptions\Throwable) {
$this->logger->error($exception->getMessage(), $exception->getContext());
} else {
$this->logger->error($exception->getMessage());
}
}
}
Testing
phpunit
Contributing
Please see CONTRIBUTING and CODE OF CONDUCT for more details., (*8)