PHPackages                             matapatos/wp-exceptions - 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. matapatos/wp-exceptions

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

matapatos/wp-exceptions
=======================

Stop returning WP\_Error. Throw exceptions instead

v2.0.0(6mo ago)2101MITPHPPHP ^8.1CI passing

Since Mar 17Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/Attributes-PHP/wp-exceptions)[ Packagist](https://packagist.org/packages/matapatos/wp-exceptions)[ RSS](/packages/matapatos-wp-exceptions/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

WP Exceptions
=============

[](#wp-exceptions)

[![Throw exceptions instead of returning WP_Error](https://raw.githubusercontent.com/Attributes-PHP/wp-exceptions/main/images/wp-exceptions-wallpaper.png)](https://raw.githubusercontent.com/Attributes-PHP/wp-exceptions/main/images/wp-exceptions-wallpaper.png)

 [![GitHub Actions Workflow Status (main)](https://camo.githubusercontent.com/8db40b54d950594b34f870fa6be6fd5a761a9dc85004b4f180d540fd03bd2b88/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f417474726962757465732d5048502f77702d657863657074696f6e732f74657374732e796d6c)](https://github.com/Attributes-PHP/wp-exceptions/actions) [![Code Coverage](https://camo.githubusercontent.com/e0c555f4f5ac5a994d6452586e876f1640adefda97a719854951ad2796f009d6/68747470733a2f2f636f6465636f762e696f2f67682f417474726962757465732d5048502f77702d657863657074696f6e732f67726170682f62616467652e7376673f746f6b656e3d384e374e394e4d474c47)](https://codecov.io/gh/Attributes-PHP/wp-exceptions) [![Latest Version](https://camo.githubusercontent.com/28aad9e72351cd888873c917fd9ec7e834eb40fe1675b34715ed2ad6a59786ce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f417474726962757465732d5048502f77702d657863657074696f6e73)](https://packagist.org/packages/Attributes-PHP/wp-exceptions) [![Supported WordPress Versions](https://camo.githubusercontent.com/024067ee308e72bf9d7b687b86053896098f0b0295cfecf93b4e5d6fc73c4e26/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f362e782d76657273696f6e733f6c6f676f3d776f72647072657373266c6162656c3d76657273696f6e73)](https://packagist.org/packages/Attributes-PHP/wp-exceptions) [![Software License](https://camo.githubusercontent.com/dabf5f4e340f5feccb28b06b6248dca0d8a052fb5caf2abd614b1a656bc2edc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e63652d4d49542d627269676874677265656e)](https://opensource.org/licenses/MIT)

---

*WP\_Error* was a cool feature in 2007 but today we should throw exceptions.

Features
--------

[](#features)

- Handles *HttpExceptions* like WP\_Error's
- Supports custom handlers for custom exceptions
- Compatible with other exception handlers (e.g. [Whoops](https://github.com/filp/whoops))

Requirements
------------

[](#requirements)

- PHP 8.1+
- WordPress 6.x

We aim to support versions that haven't reached their end-of-life.

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

[](#installation)

```
composer require attributes-php/wp-exceptions
```

How it works?
-------------

[](#how-it-works)

Once the ExceptionHandler is registered, you can start throwing exceptions

```
use Attributes\Wp\Exceptions\ExceptionHandler;

ExceptionHandler::register();
```

#### How **HttpExceptions** are displayed?

[](#how-httpexceptions-are-displayed)

WordPress itself handles how an [**HttpException**](https://github.com/Attributes-PHP/wp-exceptions/blob/main/src/HttpException.php)is displayed to the user. In a nutshell, those exceptions are converted into a [**WP\_Error**](https://developer.wordpress.org/reference/classes/wp_error/)which is then handled by WordPress via [*wp\_die*](https://developer.wordpress.org/reference/functions/wp_die/) function.

This means, that the following types of requests are supported:

- ✅ Ajax
- ✅ JSON
- ✅ JSONP
- ✅ XMLRPC
- ✅ XML
- ✅ All other types e.g. HTML

#### How to send custom HTTP headers?

[](#how-to-send-custom-http-headers)

```
throw new HttpException(headers: ['My-Header' => 'Value 123']);
```

#### How to add custom handlers?

[](#how-to-add-custom-handlers)

```
$exceptionHandler = ExceptionHandler::getOrCreate();
$exceptionHandler->onException(CustomException::class, fn($ex) => echo "A custom exception has been raised");
```

Ensure to add handlers which supports all types of possible requests e.g. JSON, XML, etc

#### Sage theme support

[](#sage-theme-support)

If you are using [*Sage*](https://github.com/roots/sage) theme, you would need to register or re-register this exception handler after the application is configured. Otherwise, this exception handler might be overrided.

```
// themes/sage/functions.php

Application::configure()
    ->withProviders([
        App\Providers\ThemeServiceProvider::class,
    ])
    ->boot();

ExceptionHandler::register(force: true); // We are using force true in case the ExceptionHandler has been registered before e.g. in a plugin
```

WP Exceptions was created by **[André Gil](https://www.linkedin.com/in/andre-gil/)** and is open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance75

Regular maintenance activity

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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

Every ~487 days

Total

3

Last Release

183d ago

Major Versions

v1.0.1-beta → v2.0.02025-11-15

PHP version history (2 changes)v1.0.0-betaPHP ^7.4|^8.0

v2.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/003429b6663925cfdb49ef53d6ce8f5af6caa9cb466b6052d4c482b23385ed39?d=identicon)[matapatos](/maintainers/matapatos)

---

Top Contributors

[![matapatos](https://avatars.githubusercontent.com/u/7942653?v=4)](https://github.com/matapatos "matapatos (34 commits)")

---

Tags

exceptionsmodern-wordpresswordpresswordpressexceptions

###  Code Quality

Static AnalysisRector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/matapatos-wp-exceptions/health.svg)

```
[![Health](https://phpackages.com/badges/matapatos-wp-exceptions/health.svg)](https://phpackages.com/packages/matapatos-wp-exceptions)
```

###  Alternatives

[tgmpa/tgm-plugin-activation

TGM Plugin Activation is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins).

1.8k222.5k13](/packages/tgmpa-tgm-plugin-activation)[aristath/kirki

Extending the WordPress customizer

1.3k73.0k4](/packages/aristath-kirki)[afragen/git-updater

A plugin to automatically update GitHub, Bitbucket, GitLab, or Gitea hosted plugins, themes, and language packs.

3.3k1.6k](/packages/afragen-git-updater)[justintadlock/hybrid-carbon

God-like post featured image script.

202.5k](/packages/justintadlock-hybrid-carbon)

PHPackages © 2026

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