adlacruzes/php-base-exception
最新稳定版本:2.5.0
Composer 安装命令:
composer require adlacruzes/php-base-exception
包简介
PHP base exception with default message and custom value
关键字:
README 文档
README
PHP base exception is a library that provides exceptions with a default message and a custom value in an easy way.
Requirements
PHP needs to be a minimum version of PHP 7.2.
Installation
The recommended way to install is through Composer.
composer require adlacruzes/php-base-exception
Usage
Create an exception that extends from BaseException.
use Adlacruzes\Exceptions\BaseException; class SomethingNotFoundException extends BaseException {}
Then the exception can be called with no arguments.
try { throw new SomethingNotFoundException(); } catch (SomethingNotFoundException $e) { echo $e->getMessage(); }
The method getMessage() returns an auto generated message based on the class name without typing anything more.
echo $e->getMessage(); // Something not found
Default message
You can choose a default message instead. Just initialize the message variable.
class SomethingNotFoundException extends BaseException { /** * @var mixed */ protected $message = 'This is a default message'; }
try { throw new SomethingNotFoundException(); } catch (SomethingNotFoundException $e) { echo $e->getMessage(); }
echo $e->getMessage(); // This is a default message
Message with contextual information
In addition to the message, you can provide more information to the exception and it will append to the result.
try { throw new SomethingNotFoundException('information'); } catch (SomethingNotFoundException $e) { echo $e->getMessage(); }
And the output will be:
echo $e->getMessage(); // Something not found: information
统计信息
- 总下载量: 37.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-10