Class IncorrectQuantityException

java.lang.Object
java.lang.Throwable
java.lang.Exception
com.goldenleaf.shop.exception.IncorrectQuantityException
All Implemented Interfaces:
Serializable

public class IncorrectQuantityException extends Exception
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 null in 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:
  • invalid reference
    com.goldenleaf.shop.model.CartItem
  • invalid reference
    com.goldenleaf.shop.model.Product#setStock(int)
  • invalid reference
    com.goldenleaf.shop.model.OrderLine#setQuantity(int)
  • Serialized Form
  • Constructor Details

    • IncorrectQuantityException

      public IncorrectQuantityException(String message)
      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 by Throwable.getMessage()
    • IncorrectQuantityException

      public IncorrectQuantityException(String message, Throwable cause)
      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 message
      cause - the root cause of this exception
      Since:
      1.2