PHPackages                             folded/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. folded/exception

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

folded/exception
================

Various kind of exception to throw for your web app.

v0.4.0(5y ago)052218MITPHPPHP &gt;=7.4.0

Since Sep 6Pushed 5y ago1 watchersCompare

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

READMEChangelogDependencies (3)Versions (6)Used By (8)

folded/exception
================

[](#foldedexception)

Various kind of exception to throw for your web app.

[![Packagist License](https://camo.githubusercontent.com/4823fa9fb2b875c99163eb214cbaa8e84d1b42e44b7ac4ac6dc7fc9dfcaa0062/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f666f6c6465642f657863657074696f6e)](https://github.com/folded-php/exception/blob/master/LICENSE) [![Packagist PHP Version Support](https://camo.githubusercontent.com/2ddf684fda759bcc98f50610300eacca68343e4e7085af29ffaf87dc2935eef7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f666f6c6465642f657863657074696f6e)](https://github.com/folded-php/exception/blob/master/composer.json#L14) [![Packagist Version](https://camo.githubusercontent.com/69abc04a0df49662a8ef10823301dd89de07899622d486891c83ece000525eff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f6c6465642f657863657074696f6e)](https://packagist.org/packages/folded/exception) [![Build Status](https://camo.githubusercontent.com/11d10292fb5b73fb0fb6ba624d9df40e07f6265b0e4d3ff9134afd7147e7ff76/68747470733a2f2f7472617669732d63692e636f6d2f666f6c6465642d7068702f657863657074696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/folded-php/exception) [![Maintainability](https://camo.githubusercontent.com/e02df0309398ed4bdb6c1304b3eb125d5c75767bbe1924bb1bdf1a7f0fb598cc/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f31613463643331326562643436333334326265662f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/folded-php/exception/maintainability) [![TODOs](https://camo.githubusercontent.com/3ba132cdcd314baceb5e357178c2e36d2a286d3650063f1ee0a604326b3a390d/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f6170692e7469636b6769742e636f6d2f62616467653f7265706f3d6769746875622e636f6d2f666f6c6465642d7068702f657863657074696f6e)](https://www.tickgit.com/browse?repo=github.com/folded-php/exception)

Summary
-------

[](#summary)

- [About](#about)
- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Examples](#examples)
- [Version support](#version-support)

About
-----

[](#about)

I created this library to share exception that I use on both of the packages that compose Folded.

These exceptions are common errors I use for my web apps, that you can also use to provide more sense to your errors instead of using the classic `Exception`.

Folded is a constellation of packages to help you setting up a web app easily, using ready to plug in packages.

- [folded/action](https://github.com/folded-php/action): A way to organize your controllers for your web app.
- [folded/config](https://github.com/folded-php/config): Configuration and environment utilities for your PHP web app.
- [folded/crypt](https://github.com/folded-php/crypt): Encrypt and decrypt strings for your web app.
- [folded/exception](https://github.com/folded-php/exception): Various kind of exception to throw for your web app.
- [folded/history](https://github.com/folded-php/history): Manipulate the browser history for your web app.
- [folded/http](https://github.com/folded-php/http): HTTP utilities for your web app.
- [folded/orm](https://github.com/folded-php/orm): An ORM for you web app.
- [folded/request](https://github.com/folded-php/request): Request utilities, including a request validator, for your PHP web app.
- [folded/routing](https://github.com/folded-php/routing): Routing functions for your PHP web app.
- [folded/session](https://github.com/folded-php/session): Session functions for your web app.
- [folded/view](https://github.com/folded-php/view): View utilities for your PHP web app.

Features
--------

[](#features)

- Contains some exception to throw
- The exceptions contains methods to set additional data (like the folder path for the `FolderNotFoundException` for example) and retrieve these data

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

[](#requirements)

- PHP version &gt;= 7.4.0
- Composer installed

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

[](#installation)

In your root project folder, run this command to install the package:

```
composer require folded/exception
```

Examples
--------

[](#examples)

Most of the examples will add additional data by not directly throwing a new instance, but rather constructing an instance and using methods to add more context.

Keep in mind you are not forced to do it, and can just throw a message like you are used to with the classic `Exception`.

Using the methods you will discover below has the advantage to be able to give more context and facilitate the debugging when using an error management services such as Sentry, with its capability to [store additional data](https://docs.sentry.io/platforms/php/enriching-error-data/additional-data/manage-context/).

- [1. FolderNotFoundException](#1-foldernotfoundexception)
- [2. MethodNotAllowedException](#2-methodnotallowedexception)
- [3. NotAFolderException](#3-notafolderexception)
- [4. UrlNotFoundException](#4-urlnotfoundexception)
- [5. HistoryNotFoundException](#5-historynotfoundexception)
- [6. RouteNotFoundException](#6-routenotfoundexception)
- [7. SessionKeyNotFoundException](7-sessionkeynotfoundexception)

### 1. FolderNotFoundException

[](#1-foldernotfoundexception)

In this example, we will throw an exception when a folder path is not found.

```
use Folded\Exceptions\FolderNotFoundException;

try {
  $exception = new FolderNotFoundException("folder foo not found");

  $exception->setFolder("foo");

  throw $exception;
} catch (FolderNotFoundException $exception) {
  echo "folder not found is {$exception->getFolder()}";
}
```

### 2. MethodNotAllowedException

[](#2-methodnotallowedexception)

In this example, we will throw an exception when an HTTP method is not allowed (HTTP status code 405).

```
use Folded\Exceptions\MethodNotAllowedException;

try {
  $exception = new MethodNotAllowedException("method GET not allowed");

  $exception->setMethodNotAllowed("GET");
  $exception->setAllowedMethods(["POST", "DELETE"]);
  $exception->setUrl("/post/store");

  throw $exception;
} catch (MethodNotAllowedException $exception) {
  $url = $exception->getUrl();
  $allowedMethods = $exception->getAllowedMethods();

  echo "method not allowed on URL $url: {$exception->getMethodNotAllowed()}";

  foreach ($allowedMethods as $allowedMethod) {
    echo "allowed method: $allowedMethod";
  }
}
```

### 3. NotAFolderException

[](#3-notafolderexception)

In this example, we will throw an exception when a path is not a folder.

```
use Folded\Exceptions\NotAFolderException;

try {
  $exception = new NotAFolderException("foo is not a folder");

  $exception->setFolder("foo");
} catch (NotAFolderException $exception) {
  echo "folder {$exception->getFolder()} is not a folder";
}
```

### 4. UrlNotFoundException

[](#4-urlnotfoundexception)

In this example, we will throw an exception when an URL is not found (HTTP status code 404).

```
use Folded\Exceptions\UrlNotFoundException;

try {
  $exception = new UrlNotFoundException("url /about-us not found");

  $exception->setUrl("/about-us");

  throw $exception;
} catch (UrlNotFoundException $exception) {
  echo "url {$exception->getUrl()} not found";
}
```

### 5. HistoryNotFoundException

[](#5-historynotfoundexception)

In this example, we will throw an exception when an history is not found on a browser history manager.

Check [folded/history](https://github.com/folded-php/history) for an example of package that deals with the browser history on back-end.

```
use Folded\Exceptions\HistoryNotFoundException;

try {
  $exception = new HistoryNotFoundException("history 1 not found");
  $exception->setIndex(1);

  throw $exception;
} catch (HistoryNotFoundException $exception) {
  echo "index {$exception->getIndex()} not found in the history";
}
```

### 6. RouteNotFoundException

[](#6-routenotfoundexception)

In this example, we will throw an exception if a route name is not found (when using a router for example).

```
use Folded\Exceptions\RouteNotFoundException;

try {
  $exception = new RouteNotFoundException("route /about-us not found");
  $exception->setRoute("/about-us");

  throw $exception;
} catch (RouteNotFoundException $exception) {
  echo "route {$exception->getRoute()} not found";
}
```

### 7. SessionKeyNotFoundException

[](#7-sessionkeynotfoundexception)

In this example, we will throw an exception if a key is not found in a session array.

```
use Folded\Exceptions\SessionKeyNotFoundException;

try {
  $exception = new SessionKeyNotFoundException("key foo not found");
  $exception->setKey("foo");

  throw $exception;
} catch (SessionKeyNotFoundException $exception) {
  echo "key {$exception->getKey()} not found";
}
```

Version support
---------------

[](#version-support)

7.37.48.0v0.1.0❌✔️❓v0.1.1❌✔️❓v0.2.0❌✔️❓v0.3.0❌✔️❓v0.4.0❌✔️❓

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.6% 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 ~6 days

Total

5

Last Release

2050d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15908747?v=4)[Anwar](/maintainers/khalyomede)[@khalyomede](https://github.com/khalyomede)

---

Top Contributors

[![khalyomede](https://avatars.githubusercontent.com/u/15908747?v=4)](https://github.com/khalyomede "khalyomede (28 commits)")[![tchapuis](https://avatars.githubusercontent.com/u/15218089?v=4)](https://github.com/tchapuis "tchapuis (1 commits)")

---

Tags

exceptionphp

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/folded-exception/health.svg)

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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