kaida-by / php-multiexception
Catch a few exceptions and show them
dev-master
2023-01-30 13:33 UTC
Requires
- php: >=7.0.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-08-29 02:44:35 UTC
README
use KaidaBy\MultiException; function checkSomethingString($string): bool { $exceptions = new MultiException(); if (mb_strlen($string) < 6) { $exceptions->add(new Exception('The string must be longer than 6 characters')); } if (!is_string($string)) { $exceptions->add(new Exception('The input parameter should be a string')); } if (preg_match('%^\p{Lu}%u', $string)) { $exceptions->add(new Exception('The line must begin with a capital letter.')); } if (!$exceptions->isEmpty()) { throw $exceptions; } return true; } try { checkSomething($thing); } catch (MultiException $exceptions) { foreach ($exceptions as $exception) { echo $exception->getMessage() . PHP_EOL; } }