Can you please give me your opinion about extending the default error message created by the InvalidStateException? At present in case the validation fails there is no chance to figure out what went wrong. And I can not believe that catching this particular Hibernate-exception in the business layer (see code below) is the right place to retrieve the info. Furthermore it is a runtime exception and thus I believe the exception is responsible for telling the user as much as possible (which might be different for a checked exception, but this is another discussion).
Code:
try {
myPersistenceLayer.save(myObject);
} catch (org.hibernate.validator.InvalidStateException e) {
// THE SOURCE OF THE VALIDATON ERROR IS LOST,
// BECAUSE NOT CONTAINED IN THE toString() OF
// THE InvalidStateException?
// just demonstration, no production code :-)
//
System.out.println(Arrays.toString(e.getInvalidValues()));
throw e;
}
Maybe the toString() should additionally contain 'Arrays.toString(e.getInvalidValues())'?
Is this a bug or feature request?
Jens
Code: