PHPackages                             constup-foss/php-exerr - 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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. constup-foss/php-exerr

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

constup-foss/php-exerr
======================

PHP errors and exceptions.

1.0.0(2w ago)04↓100%MITPHP

Since May 25Pushed 2w agoCompare

[ Source](https://github.com/constup-foss/php-exerr)[ Packagist](https://packagist.org/packages/constup-foss/php-exerr)[ Fund](https://www.buymeacoffee.com/puew3hvwvp)[ Patreon](https://www.patreon.com/c/NikolaStojiljkovic)[ RSS](/packages/constup-foss-php-exerr/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

constUP PHP Exerr
=================

[](#constup-php-exerr)

Table of Contents

- [Description](#description)
- [Installation](#installation)
- [Available exceptions](#available-exceptions)
    - [`abstract LibraryException`](#abstract-libraryexception)
- [Use](#use)
    - [Extending a base exception](#extending-a-base-exception)
    - [Throwing your exception](#throwing-your-exception)
    - [Advantages of the above architecture](#advantages-of-the-above-architecture)
- [License](#license)
- [Supporting development](#supporting-development)

[![Static Badge](https://camo.githubusercontent.com/5caa455d8debc46fb23abbadb45a733a937f3910a73fc875c2f7820468e1bb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/5caa455d8debc46fb23abbadb45a733a937f3910a73fc875c2f7820468e1bb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e)[![Packagist Downloads](https://camo.githubusercontent.com/5c0128631f5b6079a7e9c49c4cac7fc22a2f55ce2ebc64271ee7fd0e145e8308/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f6e737475702d666f73732f7068702d6578657272)](https://camo.githubusercontent.com/5c0128631f5b6079a7e9c49c4cac7fc22a2f55ce2ebc64271ee7fd0e145e8308/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f6e737475702d666f73732f7068702d6578657272)

Description
-----------

[](#description)

PHP Errors and exceptions.

This library contains a set of base exceptions with an expanded set of properties compared to PHP’s default `\Exception`. The idea is to provide standardized base exceptions that make controlling and debugging the application easier.

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

[](#installation)

```
composer require constup-foss/php-exerr
```

Available exceptions
--------------------

[](#available-exceptions)

### `abstract LibraryException`

[](#abstract-libraryexception)

Intended to be used in composer libraries. The following properties are added to the base `\Exception`:

- `string $libraryName` - Name of the library that threw the exception. Example: "constup-foss/php-exerr". Helps to identify the origin of the exception during debugging.
- `?string $debugMessage` - Debug message that can be used to identify the exact cause of the exception. This message should be used for logging purposes only and must not be displayed to the user. It should contain as much information as possible to help identify the exact cause of the exception.
- `?string $userMessage` - User-friendly message that can be displayed to the user. Must not contain sensitive information.
- `?int $httpResponseCode` - HTTP response code that should be passed as the response.
- `?bool $recoverable` - Indicates whether the exception is recoverable. If `true`, the exception should be handled gracefully and the application should continue running. If `false`, the exception should be handled and the application should terminate.

Use
---

[](#use)

### Extending a base exception

[](#extending-a-base-exception)

Here is an example of your own custom exception based on the `LibraryException`. Note that this example contains all optional (nullable) properties, but you are free to omit them in your exceptions.

```
class YourCustomException extends LibraryException
{
    /**
     * Thrown when an item in the collection is not of the expected type.
     *
     * @param string $itemType
     * @param string $expectedType
     * @param int    $index
     *
     * @return $this
     */
    public function invalidItemTypeAtIndex(
        string $itemType,
        string $expectedType,
        int $index,
    ): self {
        $this->message = 'Validation error';
        $this->code = 1;
        $this->libraryName = 'your/library-name';
        $this->debugMessage = "Invalid item type at index: {$index}. Expected: {$expectedType}. Got: {$itemType}";
        $this->userMessage = 'You have provided invalid data. Please, try again.';
        $this->httpResponseCode = 400;
        $this->recoverable = false;

        return $this;
    }
}
```

### Throwing your exception

[](#throwing-your-exception)

```
throw new YourCustomException()->invalidItemTypeAtIndex($itemType, $expectedType, $index);
```

### Advantages of the above architecture

[](#advantages-of-the-above-architecture)

- Exceptions can be classified by their Interface. When an exception that implements `LibraryExceptionInterface` is passed to an exception handler, the exception handler knows which properties to expect.
- An exception handler can classify exceptions by their class (`YourCustomException` from the example above).
- Having multiple exception methods in the same class brings the following benefits:

    - Your exceptions can be classified by their domain.
    - Managing of error codes is much easier. Each of your exceptions can have a possible range of codes. Exception codes that logically belong to the same range are not scattered across multiple files, making it easier to maintain and avoid conflicts.

License
-------

[](#license)

MIT License

- License file: [LICENSE.txt](LICENSE.txt)
- Online version:

Supporting development
----------------------

[](#supporting-development)

If you like this library or find it useful, consider buying me a nice cup of coffee. Coffee fuels open source.

[![bmac](doc/bmac.png)](doc/bmac.png)

[![default green](https://camo.githubusercontent.com/6d00276d6e09b1c1a8391562c40e2c387f266c3518fdb25a19429d30aa22ef7a/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d677265656e2e706e67)](https://www.buymeacoffee.com/puEW3HvWvP)

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance97

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

15d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ff6a24d0a2201cc6237bc92b6cd2025fbfaea471e35ded103e14a8ebf894bc0?d=identicon)[constup-foss](/maintainers/constup-foss)

---

Top Contributors

[![constup-foss](https://avatars.githubusercontent.com/u/286199137?v=4)](https://github.com/constup-foss "constup-foss (2 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/constup-foss-php-exerr/health.svg)

```
[![Health](https://phpackages.com/badges/constup-foss-php-exerr/health.svg)](https://phpackages.com/packages/constup-foss-php-exerr)
```

###  Alternatives

[beyondcode/helo-laravel

HELO Laravel debug helper

90363.7k](/packages/beyondcode-helo-laravel)[phalcon/dd

This package will add the `dd` and `dump` helpers to your Phalcon application.

24296.9k27](/packages/phalcon-dd)

PHPackages © 2026

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