Class NullCustomerException
- All Implemented Interfaces:
Serializable
Customer instance, but null is provided
or the customer reference is missing.
The Customer is a central entity in the shop domain. Many business operations
(adding items to cart, creating reviews, managing payment methods, placing orders,
applying bonus points, etc.) are performed in the context of an authenticated customer.
Passing null instead of a proper customer would break referentialIntegrity
and lead to inconsistent or orphaned data.
Typical scenarios that trigger this exception:
- Calling
CreditCard.setCustomer(Customer)withnull - Attempting to add a payment method, review, or order item without an authenticated customer
- Service-layer methods receiving a
nullcustomer from a controller or repository - Batch processing or data migration trying to associate entities with a non-existent customer
- Security context issues where the current user could not be resolved
This is a checked exception, forcing the caller to explicitly handle the missing customer case. It represents a recoverable validation/state error that commonly occurs during user-bound operations.
- Since:
- 1.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionNullCustomerException(String message) Constructs a new null-customer exception with the specified detail message.NullCustomerException(String message, Throwable cause) Constructs a new null-customer 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
-
NullCustomerException
Constructs a new null-customer exception with the specified detail message.- Parameters:
message- the detail message (e.g. "Customer cannot be null") Saved for later retrieval byThrowable.getMessage()
-
NullCustomerException
Constructs a new null-customer exception with the specified detail message and cause.Useful when wrapping lower-level errors (e.g.,
Authenticationbeing null, entity-not-found issues, lazy-initialization failures, etc.).- Parameters:
message- the detail messagecause- the root cause of this exception- Since:
- 1.2
-