ConversionException class sealed

The error a conversion service throws when a value cannot be turned into the requested type.

Catch it where a value comes from outside and a bad one should not be fatal, such as a query parameter or a line of an import file. When it happens while beans are created (a bad @Value), the start fails. It is sealed: every conversion error is either a ConversionFailedException (a converter exists but the value is bad) or a ConverterNotFoundException (nothing converts to that type).

// A page size typed by a user: fall back instead of failing.
int pageSize(String input) {
  try {
    return conversionService.convert<int>(input);
  } on ConversionException catch (error) {
    log.warn(error.message);
    return 20;
  }
}

Spring (Java):

try {
  conversionService.convert("abc", Integer.class);
} catch (ConversionException ex) {
  log.warn(ex.getMessage());
}
Implemented types

Properties

hashCode → int
The hash code for this object.
no setterinherited
message → String
What failed, naming the value and the target type.
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