---
title: "Exceptions — Trading Analytics for Laravel | Roundly"
description: "Every package exception extends TradingAnalyticsException — invalid trades, unordered sources, scales and numbers, unknown calculators or engines."
url: https://roundly-consulting.com/open-source/docs/trading-analytics-for-laravel/exceptions
language: en
---

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

[Trading Analytics for Laravel](https://roundly-consulting.com/open-source/docs/trading-analytics-for-laravel.md)

# Exceptions

Every exception extends RoundlyConsulting\\TradingAnalytics\\Exceptions\\TradingAnalyticsException (a RuntimeException), so you can catch them all with one catch:

```php
use RoundlyConsulting\TradingAnalytics\Exceptions\TradingAnalyticsException;
use RoundlyConsulting\TradingAnalytics\Facades\TradingAnalytics;

try {
    $analytics = TradingAnalytics::for($rows)->scale($scale)->calculate();
} catch (TradingAnalyticsException $e) {
    // an invalid trade row, an unordered source, a chunk size below 1, a negative scale,
    // a non-numeric value, a division by zero, an unknown calculator or engine
    report($e);
}
```

| Exception | Named constructors | Thrown when |
| --- | --- | --- |
| `InvalidTradeException` | emptyCurrency, closeBeforeOpen, nonPositiveSize, nonPositiveOpenPrice, negativeClosePrice, missingField, invalidField, invalidDirection | An empty base or quote currency, a close time before the open time, a size or open price at or below 0, a negative close price, a missing or null required field, a field of the wrong type, or a direction other than buy / sell. |
| `UnorderedTradeSourceException` | for, outOfOrder | A query passed as a trade source without an orderBy, or a realized trade that arrives after one that closed later. |
| `InvalidChunkSizeException` | tooSmall | A chunk below 1. |
| `InvalidScaleException` | negative | A negative scale. |
| `InvalidNumericOperationException` | nonNumericValue, outOfRange, fractionalExponent | A non-numeric input (INF and NAN included), an exponent above 1000, or a fractional pow() exponent. |
| `DivisionByZeroException` | make | Division by zero. |
| `UnknownCalculatorException` | notACalculator | only() / except() / calculate(only: …) given a class that is not a registered calculator. |
| `InvalidEngineException` | notAnAnalyticsEngine | TradingAnalytics::using() given a class that isn’t Analytics or a subclass of it. |

Trade::collect() is lazy: an invalid row or an out-of-order trade throws while calculate() consumes it, not when the collection is built. A query without an orderBy and a chunk below 1 throw as soon as the source is passed in.

A malformed scale or win\_rate\_period config is the one exception outside this family: it throws package-toolkit’s InvalidConfigurationException, naming the key, as soon as the engine is built.

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