I have my multi module maven project with the following structure:
+ parent - pom.xml + model - persistents - dao - model stuff... - pom.xml + service - services - services stuff... - pom.xml + utils - exceptions - pom.xml
In utils module I have some custom exceptions. The point is that, in my exceptions I want to have the change to to give the object that caused the exception, for example, let's suppose we have the persistent class User. The userDao throws an UserNotFoundException. I want to have the following constructors:
UserNotFoundException(String message, User user)
The idea is to be able to have the object that caused the exception when handling it. However, it sounds so strange to me throwing the persistent object inside an exception... Is that correct? Does it make sense throwing the object in a exception? (I think it could be usefull to see how the object is when the exception appears).