All packages
Money for Laravel
Exceptions
Every exception extends the abstract RoundlyConsulting\Money\Exceptions\MoneyException (a RuntimeException), so one catch covers the whole family. Messages are developer-facing English; the translatable surface is the validation messages.
use RoundlyConsulting\Money\Exceptions\CurrencyMismatch;
use RoundlyConsulting\Money\Exceptions\MoneyException;
try {
$total = $cartTotal->add($shippingFee);
} catch (CurrencyMismatch $e) {
// mixing currencies is a bug, not a conversion
} catch (MoneyException $e) {
// one catch for the whole family
}| Exception | Thrown when |
|---|---|
CurrencyMismatch | Arithmetic or ordering across currencies; a shared cast column would be re-denominated; a discount, cap, shipping or rate in another currency. |
UnknownCurrency | A code the registry does not know. |
InvalidCurrency | An invalid Currency definition; a custom code longer than schema.currency_length. |
CurrencyAlreadyRegistered | A duplicate registration without replace; any ISO redefinition. |
InvalidAmount | Malformed or over-long input, unrecoverable floats, ambiguous parser symbols, tampered payloads. |
RoundingNecessary | Input more precise than the target scale, without a rounding mode. |
AmountOverflow | A result beyond 65 digits; minorInt() outside int64. |
DivisionByZero | Dividing by zero, or ratioTo() a zero amount. |
InvalidAllocation | Bad allocate(), split() or allocator input. |
EmptyMoneyCollection | sum() without a currency, or min(), max(), average() of nothing. |
InvalidMoneyValue | Cast, resource or Blade misuse; corrupt stored data; precision or engine range exceeded. |
InvalidPercentage | A negative or over-precise percentage. |
InvalidRatio | A zero denominator, inverting zero, or terms beyond 80 digits. |
InvalidDiscount | Invalid discounts and discount allocations. |
InvalidMoneyConfiguration | Misconfiguration, detected at the point of use. |
FormatterUnavailable | formatting.driver = intl without ext-intl. |
ExchangeRateUnavailable | No rate, a stale rate, a future date or a failed chain. |
ExchangeRateFetchFailed | The ECB feed could not be read — HTTP error, timeout, malformed or oversized body. |
InvalidExchangeRate | A non-positive rate, a same-currency rate other than 1, or a rate without an exact decimal of up to 40 characters. |
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 cryptoBy donating, you agree to our donation terms.
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.