PHPackages                             hoa-math-community/exception - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hoa-math-community/exception

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hoa-math-community/exception
============================

The Hoa\\Exception library.

v3.0.1(1y ago)01.2k↓25%10BSD-3-ClausePHPPHP ~8.0

Since Nov 23Pushed 1y agoCompare

[ Source](https://github.com/hoa-math-community/Exception)[ Packagist](https://packagist.org/packages/hoa-math-community/exception)[ RSS](/packages/hoa-math-community-exception/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (9)Used By (10)

 [![Hoa](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)

---

 [![Build status](https://camo.githubusercontent.com/7f2a69443d5c73d3856f432ac0e4a9414b69f2120bd2beb8d247b8c22b09f909/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f686f6170726f6a6563742f457863657074696f6e2f6d61737465722e737667)](https://travis-ci.org/hoaproject/Exception) [![Code coverage](https://camo.githubusercontent.com/a581e2e10aa9273800093a8b1e1978c008b30b6422bec7df58457daf1121d5ee/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f686f6170726f6a6563742f457863657074696f6e2f6d61737465722e737667)](https://coveralls.io/github/hoaproject/Exception?branch=master) [![Packagist](https://camo.githubusercontent.com/45c1e86986c3782367671b204114010f962f59540f842bd0d297b7ec40ed45a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f612f657863657074696f6e2e737667)](https://packagist.org/packages/hoa/exception) [![License](https://camo.githubusercontent.com/a6e5fd703ec9bb133f266d307b0ced563cc1fb7530a8cd6494b26950091fb985/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f612f657863657074696f6e2e737667)](https://hoa-project.net/LICENSE)

 Hoa is a **modular**, **extensible** and **structured** set of PHP libraries.
 Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\\Exception
==============

[](#hoaexception)

[![Help on IRC](https://camo.githubusercontent.com/4dbc9c9d28c30cf1ab591f4bb8212fe4dbddc734145df532a9bb86b09878d4c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d253233686f6170726f6a6563742d6666303036362e737667)](https://webchat.freenode.net/?channels=#hoaproject)[![Help on Gitter](https://camo.githubusercontent.com/8c4c85951788ff606b1268cb3dd946be05e3054795455d0a7b9250711bc2ac05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d6769747465722d6666303036362e737667)](https://gitter.im/hoaproject/central)[![Documentation](https://camo.githubusercontent.com/7059ad5f1a363f9098686c59d432f01d7330aed9d4b6c8111d985fd64cfc6c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d6861636b5f626f6f6b2d6666303036362e737667)](https://central.hoa-project.net/Documentation/Library/Exception)[![Board](https://camo.githubusercontent.com/fd81654ba14b3aca3a713e1b471bc3fc3ba7b5bb3761ccffd6eea2e2ed1fa5ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f7267616e69736174696f6e2d626f6172642d6666303036362e737667)](https://waffle.io/hoaproject/exception)

This library allows to use advanced exceptions. It provides generic exceptions (that are sent over the `hoa://Event/Exception` event channel), idle exceptions (that are not sent over an event channel), uncaught exception handlers, errors to exceptions handler and group of exceptions (with transactions).

[Learn more](https://central.hoa-project.net/Documentation/Library/Exception).

Installation
------------

[](#installation)

With [Composer](https://getcomposer.org/), to include this library into your dependencies, you need to require [`hoa/exception`](https://packagist.org/packages/hoa/exception):

```
$ composer require hoa/exception '~2.0'
```

For more installation procedures, please read [the Source page](https://hoa-project.net/Source.html).

Testing
-------

[](#testing)

Before running the test suites, the development dependencies must be installed:

```
$ composer install
```

Then, to run all the test suites:

```
$ vendor/bin/hoa test:run
```

For more information, please read the [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#quick-usage)

We propose a quick overview of how to use generic exceptions, how to listen all thrown exceptions through events and how to use group of exceptions.

### Generic exceptions

[](#generic-exceptions)

An exception is constitued of:

- A message,
- A code (optional),
- A list of arguments for the message (à la `printf`, optional),
- A previous exception (optional).

Thus, the following example builds an exception:

```
$exception = new Hoa\Exception\Exception('Hello %s!', 0, 'world');
```

The exception message will be: `Hello world!`. The “raise” message (with all information, not only the message) is:

```
{main}: (0) Hello world!
in … at line ….

```

Previous exceptions are shown too, for instance:

```
$previous  = new Hoa\Exception\Exception('Hello previous.');
$exception = new Hoa\Exception\Exception('Hello %s!', 0, 'world', $previous);

echo $exception->raise(true);

/**
 * Will output:
 *     {main}: (0) Hello world!
 *     in … at line ….
 *
 *         ⬇
 *
 *     Nested exception (Hoa\Exception\Exception):
 *     {main}: (0) Hello previous.
 *     in … at line ….
 */
```

### Listen exceptions through events

[](#listen-exceptions-through-events)

Most exceptions in Hoa extend `Hoa\Exception\Exception`, which fire themselves on the `hoa://Event/Exception` event channel (please, see [the `Hoa\Event`library](http://central.hoa-project.net/Resource/Library/Event)). Consequently, we can listen for all exceptions that are thrown in the application by writing:

```
Hoa\Event\Event::getEvent('hoa://Event/Exception')->attach(
    function (Hoa\Event\Bucket $bucket) {
        $exception = $bucket->getData();
        // …
    }
);
```

Only the `Hoa\Exception\Idle` exceptions are not fired on the channel event.

### Group and transactions

[](#group-and-transactions)

Groups of exceptions are represented by the `Hoa\Exception\Group`. A group is an exception that contains one or many exceptions. A transactional API is provided to add more exceptions in the group with the following methods:

- `beginTransaction` to start a transaction,
- `rollbackTransaction` to remove all newly added exceptions since `beginTransaction` call,
- `commitTransaction` to merge all newly added exceptions in the previous transaction,
- `hasUncommittedExceptions` to check whether they are pending exceptions or not.

For instance, if an exceptional behavior is due to several reasons, a group of exceptions can be thrown instead of one exception. Group can be nested too, which is useful to represent a tree of exceptions. Thus:

```
// A group of exceptions.
$group           = new Hoa\Exception\Group('Failed because of several reasons.');
$group['first']  = new Hoa\Exception\Exception('First reason');
$group['second'] = new Hoa\Exception\Exception('Second reason');

// Can nest another group.
$group['third']           = new Hoa\Exception\Group('Third reason');
$group['third']['fourth'] = new Hoa\Exception\Exception('Fourth reason');

echo $group->raise(true);

/**
 * Will output:
 *     {main}: (0) Failed because of several reasons.
 *     in … at line ….
 *
 *     Contains the following exceptions:
 *
 *       • {main}: (0) First reason
 *         in … at line ….
 *
 *       • {main}: (0) Second reason
 *         in … at line ….
 *
 *       • {main}: (0) Third reason
 *         in … at line ….
 *
 *         Contains the following exceptions:
 *
 *           • {main}: (0) Fourth reason
 *             in … at line ….
 */
```

The following example uses a transaction to add new exceptions in the group:

```
$group   = new Hoa\Exception\Group('Failed because of several reasons.');
$group[] = new Hoa\Exception\Exception('Always present.');

$group->beginTransaction();

$group[] = new Hoa\Exception\Exception('Might be present.');

if (true === $condition) {
    $group->commitTransaction();
} else {
    $group->rollbackTransaction();
}
```

Documentation
-------------

[](#documentation)

The [hack book of `Hoa\Exception`](https://central.hoa-project.net/Documentation/Library/Exception)contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

```
$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open
```

More documentation can be found on the project's website: [hoa-project.net](https://hoa-project.net/).

Getting help
------------

[](#getting-help)

There are mainly two ways to get help:

- On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)IRC channel,
- On the forum at [users.hoa-project.net](https://users.hoa-project.net).

Contribution
------------

[](#contribution)

Do you want to contribute? Thanks! A detailed [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html) explains everything you need to know.

License
-------

[](#license)

Hoa is under the New BSD License (BSD-3-Clause). Please, see [`LICENSE`](https://hoa-project.net/LICENSE) for details.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance46

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 84.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~568 days

Recently: every ~765 days

Total

7

Last Release

417d ago

Major Versions

0.15.11.23 → 1.16.01.112016-01-11

1.17.01.16 → 2.17.08.302017-08-30

2.17.08.30 → v3.0.02022-12-17

PHP version history (2 changes)2.17.08.30PHP &gt;=7.1

v3.0.0PHP ~8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/14144958f1893ddd81dafbd4df8583e38792ccc089462e3cb14b80eeba32cef3?d=identicon)[hubipe](/maintainers/hubipe)

---

Top Contributors

[![Hywan](https://avatars.githubusercontent.com/u/946104?v=4)](https://github.com/Hywan "Hywan (32 commits)")[![hubipe](https://avatars.githubusercontent.com/u/617880?v=4)](https://github.com/hubipe "hubipe (2 commits)")[![Metalaka](https://avatars.githubusercontent.com/u/5406767?v=4)](https://github.com/Metalaka "Metalaka (2 commits)")[![shulard](https://avatars.githubusercontent.com/u/482993?v=4)](https://github.com/shulard "shulard (1 commits)")[![vonglasow](https://avatars.githubusercontent.com/u/1275202?v=4)](https://github.com/vonglasow "vonglasow (1 commits)")

---

Tags

libraryexception

### Embed Badge

![Health badge](/badges/hoa-math-community-exception/health.svg)

```
[![Health](https://phpackages.com/badges/hoa-math-community-exception/health.svg)](https://phpackages.com/packages/hoa-math-community-exception)
```

###  Alternatives

[league/iso3166

ISO 3166-1 PHP Library

70036.3M116](/packages/league-iso3166)[pear/pear_exception

The PEAR Exception base class.

9880.2M101](/packages/pear-pear-exception)[dekor/php-array-table

PHP Library for printing associative arrays as text table (similar to mysql terminal console)

296.6M2](/packages/dekor-php-array-table)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
