Skip to content

Commit 457238d

Browse files
committed
Initial exceptions and tests
1 parent e94e6cb commit 457238d

21 files changed

+2022
-1
lines changed

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,61 @@
1-
# php-exceptions
1+
# The helpful custom PHP exceptions
2+
3+
[![Latest Stable Version](https://poser.pugx.org/bsadnu/php-exceptions/v/stable)](https://packagist.org/packages/bsadnu/helpers-box)
4+
[![Total Downloads](https://poser.pugx.org/bsadnu/php-exceptions/downloads)](https://packagist.org/packages/bsadnu/helpers-box)
5+
[![License](https://poser.pugx.org/bsadnu/php-exceptions/license)](https://packagist.org/packages/bsadnu/helpers-box)
6+
7+
This lets you catch different-layers-specific exceptions (if needed).
8+
9+
## Installation
10+
11+
The best way to use this component is through the Composer:
12+
13+
```BASH
14+
composer require bsadnu/php-exceptions
15+
```
16+
17+
## Usage
18+
19+
- You may use exceptions within the standard throwing/catching mechanism or even extend them in any way you want:
20+
21+
```php
22+
use Bsadnu\Exception\InvalidArgumentException;
23+
24+
...
25+
26+
try {
27+
...
28+
} catch (InvalidArgumentException $exception) {
29+
...
30+
}
31+
```
32+
33+
```php
34+
use Bsadnu\Exception\TypeError;
35+
36+
...
37+
38+
throw new TypeError($message);
39+
```
40+
41+
- It is really helpful to catch the base `ExceptionInterface` sometimes. Therefore, you can control a group of exceptions. Moreover, you may add manually as many specific interfaces as you wish.
42+
43+
## More detailed description
44+
45+
All exceptions used in this library implements `\Bsadnu\Exception\ExceptionInterface`, and extend one of the SPL extensions. This way, you have several ways of catching specific extension groups:
46+
1. Catch all exceptions: `\Exception`
47+
2. Catch all exceptions thrown by the library:
48+
`\Bsadnu\Exception\ExceptionInterface`
49+
3. Catch a specific SPL exception: `\LogicException`
50+
4. Catch a specific SPL exception thrown by the library:
51+
`\Bsadnu\Exception\LogicException`
52+
53+
The base `\Bsadnu\Exception\ExceptionInterface` consists of `getUnit/setUnit` methods which can be used to describe the place of code (Unit) where an exception occurs.
54+
55+
## Contributing
56+
57+
All feedback / bug reports / pull requests are welcome.
58+
59+
## License
60+
61+
This code is licensed under the [MIT License](LICENSE).

composer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "bsadnu/php-exceptions",
3+
"description": "The helpful custom PHP exceptions",
4+
"keywords": ["PHP", "exception", "exceptions", "custom-exceptions"],
5+
"type": "library",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Stas Bannikov",
10+
"email": "sab.ukraine@gmail.com"
11+
}
12+
],
13+
"require": {
14+
"php": "^7.1"
15+
},
16+
"require-dev": {
17+
"phpunit/phpunit": "~4"
18+
},
19+
"autoload": {
20+
"psr-4": {
21+
"Bsadnu\\Exception\\": "src/"
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)