christianjbrown / user-friendly-exception
A tiny PHP library providing a UserFriendlyException whose message is safe to display directly to end users.
Package info
github.com/christianjbrown/user-friendly-exception-php
pkg:composer/christianjbrown/user-friendly-exception
Requires
- php: ^8.5
Requires (Dev)
- christianjbrown/code-quality-scripts: ^1.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-01 13:33:42 UTC
README
This is an extremely simple PHP library for a reusable UserFriendlyException class.
Using UserFriendlyException indicates that the $message passed is safe to and clear enough to be bubbled up to the end user.
✔️ Prerequisites
💡 If you're on MacOS and have Homebrew, PHP and Composer will install with brew install composer.
🏗️ Installation
For your composer-enabled project:
composer require christianjbrown/user-friendly-exception
💻 Usage
Throwing the exception after catching a non-user-friendly exception.
use ChristianBrown\UserFriendlyException\UserFriendlyException; use RuntimeException; try { // ... // Technical issue here // ... } catch (RuntimeException $e) { throw new UserFriendlyException('We encountered a technical issue. Please try again later', 0, $e); }
Later passing the contents of UserFriendlyException directly to the end users
use ChristianBrown\UserFriendlyException\UserFriendlyExceptionInterface; use Throwable; $app = new Application(); try { $responseText = $app->run(); $response = new Response($responseText, 200); } catch (UserFriendlyExceptionInterface $e) { $response = new Response($e->getMessage(), $e->getCode() ?: 500); } catch (Throwable $e) { $response = new Response('An unknown error occurred, try again later', 500); } return $response;
📝 Changelog
Notable changes in each release are listed in CHANGELOG.md.
📄 License
Released under the MIT License.