bsadnu / php-exceptions
The helpful custom PHP exceptions and exception interfaces
Installs: 1 632
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.1
This package is not auto-updated.
Last update: 2024-11-15 10:47:03 UTC
README
This lets you catch different-layers-specific exceptions (if needed).
Installation
The best way to use this component is through the Composer:
composer require bsadnu/php-exceptions
Usage
- You may use exceptions within the standard throwing/catching mechanism or even extend them in any way you want:
use Bsadnu\Exception\Base\InvalidArgumentException; ... try { ... } catch (InvalidArgumentException $exception) { ... }
use Bsadnu\Exception\Base\TypeError; ... throw new TypeError($message);
- It is really helpful to catch either the base
BaseExceptionInterface
or any other. Therefore, you can control a group of exceptions. Moreover, you may add manually as many specific interfaces as you wish.
More detailed description
All exceptions used in this library implements \Bsadnu\Exception\Interfaces\BaseExceptionInterface
, and extend one of the SPL extensions. This way, you have several ways of catching specific extension groups:
- Catch all exceptions:
\Exception
- Catch all exceptions thrown by the library:
\Bsadnu\Exception\Interfaces\BaseExceptionInterface
- Catch a specific SPL exception:
\LogicException
- Catch a specific exception thrown by the library:
\Bsadnu\Exception\Base\LogicException
Contributing
All feedback / bug reports / pull requests are welcome.
License
This code is licensed under the MIT License.