library multi-exception
MultiException
ntk-andr/multi-exception
MultiException
- Friday, February 3, 2017
- by ntk-andr
- Repository
- 1 Watchers
- 0 Stars
- 4 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 1 Versions
- 0 % Grown
MultiException
Usage Example
use NtkAndr\MultiException;
function checkPassword($passwd): bool
{
$errors = new MultiException();
if (empty($passwd)) {
$errors->add(new Exception('Empty password'));
}
if (strlen($passwd) < 6) {
$errors->add(new Exception('The password is too short'));
}
if (!preg_match('~\d~', $passwd)) {
$errors->add(new Exception('The password doesn\'t contain numbers'));
}
if (!$errors->isEmpty()) {
throw $errors;
}
return true;
}
try {
checkPassword('');
} catch (MultiException $errors) {
foreach ($errors as $error) {
echo $error->getMessage() . "\n";
}
}