pioniro / contextable-exception
Adds context to your exceptions
Installs: 2 951
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
This package is auto-updated.
Last update: 2025-03-01 00:30:47 UTC
README
Is a common interfaces for adding a context in your exceptions.
It may be useful for providing more context data in logger (or sentry, etc) more context data
before:
function badFunction($id) { throw new \Exception(sprintf('bad Id: %d', $id)); }
after:
use Pioniro\ContextableException\ContextableInterface; use Pioniro\ContextableException\ContextableTrait; class MyException extends \Exception implements ContextableInterface { use ContextableTrait; } function badFunction($id) { throw (new MyException('bad Id'))->addContext(['id' => $id]); }
OR
use Pioniro\ContextableException\ContextableInterface; function badSuperFunction($id, $name) { try { badThirdPartyFunction($id); } catch (ContextableInterface $e) { $e->addContext(['name' => $name]); throw $e; } }
Did you see this? We provide more data for exception
That's why this library is.