dhii / exception
Standards-compliant exception classes
Installs: 13 110
Dependents: 21
Suggesters: 3
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 1
Requires
- php: ^5.4 | ^7.0
- dhii/exception-interface: ^0.2
- dhii/i18n-helper-base: ^0.1
- dhii/normalization-helper-base: ^0.1
Requires (Dev)
- codeclimate/php-test-reporter: <=0.3.2
- dhii/php-cs-fixer-config: ^0.1
- dhii/stringable-interface: ^0.1
- phpunit/phpunit: ^4.8
- ptrofimov/xpmock: ^1.1
Replaces
- dhii/exception-helper-base: 0.1-alpha1|0.1-alpha2
This package is auto-updated.
Last update: 2024-10-07 05:12:19 UTC
README
Standards-compliant exception classes.
Details
This package contains concrete implementations of classes that implement
interfaces in dhii/exception-interface
. This provides developers with
ready-made, standards-compliant classes that can be safely instantiated and
throw
n to signal the various errors. The concrete exceptions will usually
have a corresponding factory trait, and the factory methods of those traits
are the recommended way of creating new exception instances (after service
definition, of course).
Implementations in this package also have the following features aimed to become more standards-compliant:
- A stringable is accepted everywhere, where a string can be passed.
- All parameters can be passed
null
to signal default value (which may be notnull
).
Consumers, i.e. code that attempts to catch
, should not depend on these
classes. Instead, consumers should depend on the interfaces of
dhii/exception-interface
.
Creating New Exceptions
Sometimes, there is a need to create a new exception class, such as to implement a new standard (like dhii/action-interface
),
or perhaps to implement two unrelated interfaces (imagine an object that implements both Dhii\Action\ActionInterface
and Mouf\Utils\Action\ActionInterface
). In this case, implementing some of the features of Dhii exceptions may
take an un-necessarily long time. This package provides a way to make creating new exceptions faster.
- If you need to extend a class other than
Exception
, thenExceptionTrait
helps by combining common traits used by exceptions, which will initialize the class, while normalizing some values. SeeDhii\Exception\InvalidArgumentException
for an example. - If you need to extend the root
Exception
, then the quickest way is by instead extendingDhii\Exception\AbstractBaseException
. SeeDhii\Exception\Exception
for an example. As demonstrated, all basic initialization and normalization can be achieved by calling_initBaseException()
in the constructor, after which custom initialization procedure may be added.