wernerdweight / enhanced-exception
适用于其他项目的通用增强异常
2.0.0
2023-02-21 17:23 UTC
Requires
- php: >=8.1
- thecodingmachine/safe: ^2.4
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-21 20:28:00 UTC
README
适用于其他项目的通用增强异常
安装
- 使用Composer下载
composer require wernerdweight/enhanced-exception
- 定义你的异常
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!', ]; }
- 使用你的异常
throw new MyException(MyException::EXCEPTION_DIDNT_EXPECT_SPANISH_INQUISITION, [$user->getUsername()]); // will throw `Didn't expect Spanish inquisition to reach user Ferdinand II!`