Class IncorrectQuantityException
java.lang.Object
java.lang.Throwable
java.lang.Exception
com.goldenleaf.shop.exception.IncorrectQuantityException
- All Implemented Interfaces:
Serializable
Checked exception thrown when an attempt is made to set or update a quantity
(e.g., product stock, items in cart, order line quantity) with an invalid or
unacceptable value.
According to the business rules of the shop, quantity values must always satisfy:
- Be greater than or equal to zero (negative quantities are not allowed)
- Not exceed available stock when adding to cart or creating orders
- Be a positive integer when placing an order (usually ≥ 1)
- Never be
nullin persisted entities
Typical scenarios that trigger this exception:
- User tries to add a negative or zero number of items to the shopping cart
- Attempting to order more items than currently available in stock
- Admin or warehouse tool mistakenly setting negative stock levels
- Data import or integration process submitting invalid quantity values
- Cart manipulation or checkout validation detecting inconsistent quantities
This is a checked exception, forcing the caller to handle invalid quantity situations explicitly. It represents a recoverable business-rule violation that frequently occurs during cart operations, order placement, and inventory management.
- Since:
- 1.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionIncorrectQuantityException(String message) Constructs a new incorrect-quantity exception with the specified detail message.IncorrectQuantityException(String message, Throwable cause) Constructs a new incorrect-quantity exception with the specified detail message and cause. -
Method Summary
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
IncorrectQuantityException
Constructs a new incorrect-quantity exception with the specified detail message.- Parameters:
message- the detail message (e.g. "Quantity cannot be negative or zero") Saved for later retrieval byThrowable.getMessage()
-
IncorrectQuantityException
Constructs a new incorrect-quantity exception with the specified detail message and cause.Useful when wrapping lower-level errors (e.g., arithmetic overflow, stock-check failure, validation framework issue, or constraint violation).
- Parameters:
message- the detail messagecause- the root cause of this exception- Since:
- 1.2
-