wernerdweight/enhanced-exception

Generic enhanced exception to be used in other projects

2.0.0 2023-02-21 17:23 UTC

This package is auto-updated.

Last update: 2024-03-21 19:29:28 UTC


README

Generic enhanced exception to be used in other projects

Build Status Latest Stable Version Total Downloads License

Instalation

  1. Download using composer
composer require wernerdweight/enhanced-exception
  1. Define your exceptions
use WernerDweight\EnhancedException\Exception\AbstractEnhancedException;

class MyException extends AbstractEnhancedException
{
    /** @var int */
    public const EXCEPTION_SOMETHING_BAG_HAPPENED = 1;
    /** @var int */
    public const EXCEPTION_DIDNT_EXPECT_SPANISH_INQUISITION = 2;

    /** @var string[] */
    protected static $messages = [
        self::EXCEPTION_SOMETHING_BAG_HAPPENED => 'Something bad happened! Helpful, I know.',
        self::EXCEPTION_DIDNT_EXPECT_SPANISH_INQUISITION => 'Didn\'t expect Spanish inquisition to reach user %s!',
    ];
}
  1. Use your exceptions
throw new MyException(MyException::EXCEPTION_DIDNT_EXPECT_SPANISH_INQUISITION, [$user->getUsername()]);
// will throw `Didn't expect Spanish inquisition to reach user Ferdinand II!`