https://github.com/thecodingmachine/utils.composite-exception
A utility exception class that can aggregates several exceptions into one. Useful for aggregating exceptions triggered in loops.
https://github.com/thecodingmachine/utils.composite-exception
Last synced: about 1 year ago
JSON representation
A utility exception class that can aggregates several exceptions into one. Useful for aggregating exceptions triggered in loops.
- Host: GitHub
- URL: https://github.com/thecodingmachine/utils.composite-exception
- Owner: thecodingmachine
- License: mit
- Created: 2015-09-08T14:26:02.000Z (almost 11 years ago)
- Default Branch: 1.0
- Last Pushed: 2018-02-28T10:23:32.000Z (over 8 years ago)
- Last Synced: 2025-04-01T18:02:14.936Z (about 1 year ago)
- Language: PHP
- Size: 3.91 KB
- Stars: 1
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://packagist.org/packages/mouf/utils.composite-exception)
[](//packagist.org/packages/mouf/utils.composite-exception)
[](https://packagist.org/packages/mouf/utils.composite-exception)
[](https://scrutinizer-ci.com/g/thecodingmachine/utils.composite-exception/?branch=1.0)
[](https://travis-ci.org/thecodingmachine/utils.composite-exception)
[](https://coveralls.io/github/thecodingmachine/utils.composite-exception?branch=1.0)
# Composite exception
This project contains a simple PHP exception that can aggregate multiple exceptions in one.
The rationale behind this idea is to allow exceptions to be triggered in loops, and to throw only one at the end of your script:
## Installation
You can install this package through Composer:
```json
{
"require": {
"mouf/utils.composite-exception": "~1.0"
}
}
```
The packages adheres to the [SemVer](http://semver.org/) specification, and there will be full backward compatibility
between minor versions.
## Usage
This package contains a `CompositeException` class with 2 methods: `add(\Throwable $e)` and `isEmtpy()`.
Typical usage:
```php
use Mouf\Utils\CompositeException;
$compositeException = new CompositeException();
foreach (...) {
try {
// Do stuff
} catch (\Exception $e) {
// Add exceptions to the composite exception
$compositeException->add($e);
}
}
if (!$compositeException->isEmpty()) {
// If not empty, let's throw the composite exception.
throw $compositeException;
}
```