Each different event should have its own unique exception.
This is related to the SRP in the way that each event is different, so the exception. It is encouraged to provide custom exceptions for each different event.
👶🏿 Is like naming your children... Don't get two kids named Braulio!
The exception name must be descriptive as possible.
Use names that explicitly explain the context of the exception. For example,
SomeException is less descriptive than
🙈 All the info needed to tell what's the event about should be in the exception name
Dockblock summary should be provided at class level.
- Must be named with
- Must extend
- Must be located at
# Throwing Exceptions
The exception message must explain the event.
Provide rich messages with plenty context for the event, like arguments, how exactly the event was triggered, paths or any additional context. It is encouraged to provide a hint for the developer dealing with the situation.
use Chevere\Exceptions\Core\Exception; use Chevere\Components\Message\Message; thrown new Exception( (new Message('An error happened when opening %path% when trying to %action% for %id%)) ->strong('%path%', '/the/path/') ->code('%action%', 'register') ->code('%id%', '123') );