mouf / utils.composite-exception
该项目包含一个简单的PHP异常,可以将多个异常合并为一个。
v1.0.0
2015-09-18 15:40 UTC
Requires (Dev)
- phpunit/phpunit: ~4.0
- satooshi/php-coveralls: dev-master
README
复合异常
该项目包含一个简单的PHP异常,可以将多个异常合并为一个。这个想法的依据是允许异常在循环中触发,并在脚本结束时只抛出一个异常
安装
您可以通过Composer安装此包
{ "require": { "mouf/utils.composite-exception": "~1.0" } }
该包遵循SemVer规范,并且不同小版本之间将保持完全向后兼容。
用法
此包包含一个名为CompositeException
的类,具有两个方法:add(\Throwable $e)
和isEmpty()
。
典型用法
use Mouf\Utils\CompositeException; $compositeException = new CompositeException(); foreach (...) { try { // Do stuff } catch (\Exception $e) { // Add exceptions to the composite exception $compositeException->add($e); } } if (!$compositeException->isEmpty()) { // If not empty, let's throw the composite exception. throw $compositeException; }