---
title: "Exceptions — Permissions for Laravel | Roundly"
description: "One exception family — PermissionException, RoleDoesNotExist and PermissionDoesNotExist — with translatable messages."
url: https://roundly-consulting.com/open-source/docs/permissions-for-laravel/exceptions
language: en
---

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

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

# Exceptions

Every error the package raises extends PermissionException (a RuntimeException), so a single catch handles the whole family:

| Exception | Thrown when |
| --- | --- |
| `PermissionDoesNotExist` | Granting, revoking or syncing a permission name that is not registered. |
| `RoleDoesNotExist` | Assigning, removing or syncing a role name that is not registered. |
| `PermissionException` | A grant argument is not a string, a backed enum or the expected model, or a model instance has not been saved yet; the holder lacks HasRoles (role writes) or HasPermissions (permission writes) or has no key; syncFrom() got a class that is not a backed enum. Also the base class of the two above. |

```php
use RoundlyConsulting\Permissions\Exceptions\PermissionDoesNotExist;
use RoundlyConsulting\Permissions\Exceptions\PermissionException;
use RoundlyConsulting\Permissions\Exceptions\RoleDoesNotExist;
use RoundlyConsulting\Permissions\Facades\Permissions;
use RoundlyConsulting\Permissions\Models\Permission;

try {
    Permissions::for($user)->assignRole('auditor');
} catch (RoleDoesNotExist $e) {
    // There is no role named "auditor".
}

try {
    Permissions::for($role)->givePermissionTo('reports.export');
} catch (PermissionDoesNotExist $e) {
    // There is no permission named "reports.export".
}

try {
    Permissions::for($role)->givePermissionTo(new Permission(['name' => 'draft']));
} catch (PermissionException $e) {
    // Cannot grant an unsaved permission model; persist it before granting.
}

try {
    Permissions::for($role)->assignRole('editor');
} catch (PermissionException $e) {
    // A Role holds permissions, never roles — it has no HasRoles trait.
}
```

Messages go through Laravel’s translator, so you can translate them in your own lang files. Checks — hasRole() and hasPermissionTo() — never throw; an unknown name returns false.

## 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/permissions-for-laravel.md)
