The default PHP exception is very basic.
It only contains a message and a code.
This package aims to make exceptions more useful by allowing to add context.
- Add context to exceptions
- Add a stacktrace to exceptions
- Allow basic configuration
- Context
- format
- depth
- verbosity
- keys to hide/ignore
- default context
- custom serializers
- Stacktrace
- format
- depth
- verbosity
- Logs
- format
- depth
- verbosity
- logger class
- Exceptions
- decorators
- Context
- Custom error handler
- HTTP error extensions ("NotFound" errors that should result automatically in 404 responses)
- Switch to https://github.com/captainhookphp/captainhook for git hooks
composer require fanmade/rich-exceptions
<?php
use Fanmade\RichExceptions\RichException;
class YourException extends RichException
{
// ...
}
try {
throw YourException::createWithContext(
message: 'Something went wrong',
code: 420,
context: [ 'foo' => 'bar', 'bar' => 'baz']
);
}
catch (YourException $exception) {
Monlog::error($exception->getMessage(), $exception->getContextArray());
throw $exception;
}