---
title: "Exceptions — Advertisements for Laravel | Roundly"
description: "The package’s exception base, InvalidTargeting, AdvertisementNotActive and AdvertisementNotInPlacement, plus money, sluggable and toolkit errors."
url: https://roundly-consulting.com/open-source/docs/advertisements-for-laravel/exceptions
language: en
---

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

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

# Exceptions

The package’s own errors extend RoundlyConsulting\\Advertisements\\Exceptions\\AdvertisementException. Prices, slugs and config are validated by the sibling packages, which throw their own typed exceptions:

| Exception | When |
| --- | --- |
| `AdvertisementException` | Base class for the package’s own errors (a RuntimeException) — catch the whole surface with one type. |
| `InvalidTargeting` | A value other than a Targeting or null assigned to targeting. |
| `AdvertisementNotActive` | for($ad)->track() on an ad that isn’t live right now — a draft, scheduled, expired or archived ad credits nothing. |
| `AdvertisementNotInPlacement` | for($ad)->track($placement) with a placement the ad doesn’t run in — a forged or stale click URL can’t credit a zone. |
| `InvalidMoneyValue` | Anything but Money\|null assigned to price, or an amount wider than int64 on SQLite (money-for-laravel). |
| `CurrencyMismatch` | A price in another currency assigned to a priced ad — set currency first (money-for-laravel). |
| `RoundingNecessary` | fromDecimal() with more decimals than the currency allows (money-for-laravel). |
| `SlugAlreadyTakenException` | A manual placement or category slug that’s already taken (sluggable-for-laravel). |
| `InvalidConfigurationException` | A config value of the wrong shape, naming the key: a model key that isn’t the packaged model or a subclass, an unrecognised key\_type, bool or match\_when\_unknown value, a string setting set to a non-string, or a bad or blank responsive width (package-toolkit-for-laravel). |
| `InvalidArgumentException` | media.text\_ad\_view names a view that doesn’t exist. |

```php
use RoundlyConsulting\Advertisements\DataTransferObjects\AdvertisementData;
use RoundlyConsulting\Advertisements\Exceptions\AdvertisementException;
use RoundlyConsulting\Advertisements\Models\Placement;
use RoundlyConsulting\Money\Exceptions\MoneyException;
use RoundlyConsulting\Sluggable\Exceptions\SlugAlreadyTakenException;

try {
    $ad->targeting = ['countries' => ['SK']];   // not a Targeting instance
} catch (AdvertisementException $e) {
    // InvalidTargeting — one catch covers the package's own errors
}

try {
    AdvertisementData::fromDecimal(name: 'Bike', amount: '19.999');   // finer than a cent
} catch (MoneyException $e) {
    // RoundingNecessary — money's errors share the MoneyException base
}

try {
    Placement::query()->create(['name' => ['en' => 'Sidebar'], 'slug' => 'sidebar']);
} catch (SlugAlreadyTakenException $e) {
    // a manual placement/category slug is never silently suffixed
}
```

Money exceptions extend RoundlyConsulting\\Money\\Exceptions\\MoneyException; SlugAlreadyTakenException lives in RoundlyConsulting\\Sluggable\\Exceptions and InvalidConfigurationException in RoundlyConsulting\\PackageToolkit\\Exceptions.

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