mouf / utils.composite-exception
This project contains a simple PHP exception that can aggregate multiple exceptions in one.
Installs: 248 278
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 6
Forks: 1
Open Issues: 0
Requires (Dev)
- phpunit/phpunit: ~4.0
- satooshi/php-coveralls: dev-master
README
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:
{ "require": { "mouf/utils.composite-exception": "~1.0" } }
The packages adheres to the SemVer 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:
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; }