yiisoft/friendly-exception
An interface for friendlier exception
Maintainers
Requires
- php: 7.4.* || 8.0 - 8.5
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8.3
- maglnet/composer-require-checker: ^3.8 || ^4.3
- phpunit/phpunit: ^9.6.22
- spatie/phpunit-watcher: ^1.23.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
BSD-3-Clause c6c36fd60a0b4f1514882d2ce8395f54352ec967
This package is auto-updated.
Last update: 2026-06-18 23:35:28 UTC
README
Yii Friendly Exception
👁 Latest Stable Version
👁 Total Downloads
An exception interface that provides a friendly name and a possible solution. Error handlers may consider the interface to render additional information right at the error screen.
Example of implementation in Yii Error Handler:
👁 Frendly exceptionRequirements
- PHP 7.4 - 8.5.
Installation
The package could be installed with Composer:
composer require yiisoft/friendly-exception
General usage
Implementing friendly exception
To make exception friendly require this package and implement FriendlyExceptionInterface:
use Yiisoft\FriendlyException\FriendlyExceptionInterface; class RequestTimeoutException extends \RuntimeException implements FriendlyExceptionInterface { public function getName(): string { return 'Request timed out.'; } public function getSolution(): ?string { return <<<'SOLUTION' Likely it is a result of resource request is not responding in a timely fashion. Try increasing timeout. SOLUTION; } }
When returning solution consider the following best practices:
- Make solution description as short as possible.
- Do not use HTML tags.
- Use simple markdown.
Handling friendly exception
To make your exception handler render friendly exceptions:
use Yiisoft\FriendlyException\FriendlyExceptionInterface; class ThrowableHandler { public function handle(\Throwable $t) { if ($t instanceof FriendlyExceptionInterface) { // additional handling } // regular handling } }
Do not forget to render markdown.
Documentation
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Friendly Exception is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.
Maintained by Yii Software.
