The library is designed to be extensible while maintaining taxonomy integrity.
- Extend a Family: Always extend an existing concrete exception class (e.g.,
ValidationMaatifyException). - Define Default Code: Override
defaultErrorCode()to return the correctErrorCodeEnumvalue. - Define Constructor: If necessary, provide a default message.
use Maatify\Exceptions\Enum\ErrorCodeEnum;use Maatify\Exceptions\Exception\Validation\ValidationMaatifyException;
class InvalidEmailException extends ValidationMaatifyException
{
protected function defaultErrorCode(): ErrorCodeEnum
{
return ErrorCodeEnum::INVALID_ARGUMENT;
}
}If you need a new exception family (e.g., PaymentProcessingError), you must:
- Add to
ErrorCategoryEnum: (Requires library update) - Add to
ErrorCodeEnum: (Requires library update) - Create Abstract Base Class: Extend
MaatifyExceptionand implementdefaultCategory(). - Register in
MaatifyException::SEVERITY_RANKING: (Requires library update) - Register in
MaatifyException::ALLOWED_ERROR_CODES: (Requires library update)
Note: Adding new families requires modifying the core library itself. Consider if your exception fits into an existing category (e.g., PaymentProcessingError -> System or BusinessRule).