I have a bunch of entities that I do CRUD on, ex. Car, Boat, Banana, etc. All of these have similar exceptions that I throw when something goes wrong. For example, if I'm trying to retrieve something but it doesn't exist I throw an EntityNotFoundException
(defined by me, not jpa), or if I'm creating something but it hits some unique constraint I throw an EntityAlreadyExistsException
.
What I'm worried about is that I have (or will have) 60 classes that are coupled to these exceptions I defined in another utility library class. If the jar is missing then there's red everywhere, so I can visually see the coupling.
Is there a way around this? I'm reusing these exceptions because they're all for the same purpose and I'd hate to duplicate code (ex: duplicate the exceptions for every package), so in my mind it makes sense that it'd be used everywhere, but something about it makes me feel uneasy.
Thanks.