---
title: "Exceptions — Enums for Laravel | Roundly"
description: "EnumException — thrown by lookups, random(), validationRule(), untranslated() and invalid label groups — extends InvalidArgumentException."
url: https://roundly-consulting.com/open-source/docs/enums-for-laravel/exceptions
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Enums for Laravel](https://roundly-consulting.com/open-source/docs/enums-for-laravel.md)

# Exceptions

fromName() and fromLabel() throw RoundlyConsulting\\Enums\\Exceptions\\EnumException when no case matches; random() throws it on an enum with no cases, validationRule() on a value it can’t write into an in: rule that reads back unchanged, and untranslated() on an enum without #\[TranslatedLabels\]. An invalid #\[TranslatedLabels\] group throws it from readable() — so from every label method — on first use. It extends PHP’s InvalidArgumentException, so either catch works:

```php
use RoundlyConsulting\Enums\Exceptions\EnumException;

try {
    NewsCategory::fromName('Breaking');
} catch (EnumException $e) {
    $e->getMessage();
    // "No case named [Breaking] exists on enum [App\Enums\NewsCategory]."
}

try {
    NewsCategory::fromLabel('Breaking News');
} catch (InvalidArgumentException $e) {
    // EnumException extends InvalidArgumentException, so this catches it too
}
```

It has six named constructors:

| Named constructor | Thrown by | Message |
| --- | --- | --- |
| `EnumException::nameNotFound(string $enum, string $name)` | `fromName()` | No case named \[{name}\] exists on enum \[{enum}\]. |
| `EnumException::labelNotFound(string $enum, string $label)` | `fromLabel()` | No case with label \[{label}\] exists on enum \[{enum}\]. |
| `EnumException::noCases(string $enum)` | `random()` | Enum \[{enum}\] has no cases. |
| `EnumException::valueNotRepresentable(string $enum, string $value)` | `validationRule()` | Value \[{value}\] of enum \[{enum}\] cannot be written into an in: rule that reads back unchanged; validate it with Rule::enum() instead. |
| `EnumException::invalidLabelGroup(string $enum, string $group)` | readable() — so every label method — and untranslated() | Enum \[{enum}\] declares an invalid #\[TranslatedLabels\] group \[{group}\]: a group must not be blank or start or end with whitespace, '.' or ':'. |
| `EnumException::labelsNotTranslated(string $enum)` | `untranslated()` | Enum \[{enum}\] has no #\[TranslatedLabels\] attribute, so it has no translation keys to check. |

EnumException is deliberately not final, so you can extend it. For user input, prefer the tryFrom\* variants plus validation, and keep from\* for trusted data, where a miss is a bug worth surfacing.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/enums-for-laravel.md)
