ConstraintViolationException class

The exception a @Validated() bean throws when a call's arguments or its return value break their constraints.

It means the caller passed invalid data (or the method returned it), and lists every violation. The method does not run when the arguments are invalid. Catch it where you can tell the user; the web starter does not turn it into a 400 by itself, so an uncaught one reaching a controller is a 500. Add an @ExceptionHandler for it when clients can cause it. A @Valid() request body is reported differently, with a MethodArgumentNotValidException.

// The service rejects the empty address before running.
try {
  registration.register('');
} on ConstraintViolationException catch (e) {
  log.warning(e.message); // register.email: must not be blank
}

Spring (Java):

} catch (ConstraintViolationException e) {
  e.getConstraintViolations();
}
Implemented types

Constructors

ConstraintViolationException(List<ConstraintViolation> constraintViolations, [String? message])
An exception for constraintViolations; message defaults to their path: message pairs joined with , , as Hibernate Validator writes it.

Properties

constraintViolations → List<ConstraintViolation>
Every violation found, in the order they were checked.
final
hashCode → int
The hash code for this object.
no setterinherited
message → String
A one-line summary, such as register.email: must not be blank; fine for logs, not meant for end users.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited