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:


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.


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

if (!$compositeException->isEmpty()) {
    // If not empty, let's throw the composite exception.
    throw $compositeException;

Found a typo? Something is wrong in this documentation? Just fork and edit it!