mouf/utils.composite-exception

This project contains a simple PHP exception that can aggregate multiple exceptions in one.

v1.0.0 2015-09-18 15:40 UTC

This package is auto-updated.

Last update: 2024-10-15 04:39:43 UTC


README

Latest Stable Version Latest Unstable Version Total Downloads Scrutinizer Code Quality Build Status Coverage Status

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;
}