---
title: "Exceptions — Metrics for Laravel | Roundly"
description: "Every exception extends MetricsException — what each one means, when it is thrown, and how to catch the whole family at once."
url: https://roundly-consulting.com/open-source/docs/metrics-for-laravel/exceptions
language: en
---

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

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

# Exceptions

All exceptions extend the abstract RoundlyConsulting\\Metrics\\Exceptions\\MetricsException (itself an Exception), so one catch covers the whole family:

| Exception | Thrown when |
| --- | --- |
| `IncompleteMetricException` | An inline builder resolves before an aggregate (count, sum, average, max, min) was called. |
| `InvalidConfigurationException` | A metrics.\* config value is present but unusable — e.g. a METRICS\_CACHE\_TTL that isn’t a whole number of seconds between 1 and 31536000, a METRICS\_CACHE\_ENABLED that isn’t a boolean spelling, an unknown default\_range or default\_unit, a non-integer precision, a timezone, cache.store, cache.prefix or partition.other\_label that isn’t a string, or a trend\_drivers entry that isn’t a QueryExpression class. |
| `InvalidRangeException` | A range string can’t be resolved to a Period, or ALL is used where a bounded window is needed (e.g. compareTo(Period::All)). |
| `InvalidUnitException` | A trend query expression receives a unit it doesn’t support. |
| `MissingTrendQueryExpressionException` | A trend runs on a database driver with no registered QueryExpression. |
| `UnexpectedResultException` | A typed metric’s calculate() returned another result type than its base promises (e.g. a Value returning a TrendResult). |
| `UnknownMetricException` | Metrics::get(), Metrics::forget() or a dashboard names an unregistered key. |

```php
use RoundlyConsulting\Metrics\Exceptions\MetricsException;
use RoundlyConsulting\Metrics\Exceptions\UnknownMetricException;
use RoundlyConsulting\Metrics\Facades\Metrics;

try {
    return Metrics::get($key)->toArray();
} catch (UnknownMetricException $e) {
    abort(404, $e->getMessage());
} catch (MetricsException $e) {
    report($e);
    abort(500);
}
```

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