This repository contains a set of useful exception classes.
The exception classes interface is extended with array of context data, because often the message and the code are not enough to debug.
Using Composer:
composer require zeeproject/exceptionsThrow exceptions as usual, but you are able also to add context values:
throw new InvalidArgumentException('Something went wrong', [
'key' => 'value',
]);Now you can handle this exception, e.q. your error handler may log error details:
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());
}
}
}phpunitPlease see CONTRIBUTING and CODE OF CONDUCT for more details.