ConversionException class
Exception thrown when a type conversion fails.
ConversionException captures rich diagnostic context including:
- The original error or message that triggered the failure.
- A context map with method name, input/output types, and parameters.
- A stackTrace for debugging.
Use fullReport to generate detailed JSON output for logging or debugging.
Example
try {
Convert.toInt('not-a-number');
} on ConversionException catch (e) {
print(e.fullReport()); // Detailed diagnostic output
}
See also: ConvertConfig.onException for global error hooks.
- Implemented types
Constructors
-
ConversionException({required Object? error, required Map<
String, dynamic> context, StackTrace? stackTrace}) -
Creates a conversion exception with the originating
errorand diagnosticcontext. -
ConversionException.nullObject({required Map<
String, dynamic> context, required StackTrace stackTrace}) -
Creates an exception for
nullor unsupported source objects.factory
Properties
-
context
→ Map<
String, dynamic> -
Context metadata captured at the time of the conversion attempt.
final
- error → Object?
-
Original error or message that triggered the failure.
final
- errorType → String
-
String representation of error's runtime type.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stackTrace → StackTrace
-
Stack trace captured when the exception was created.
final
Methods
-
fullReport(
) → String - Generates an indented JSON report of the full conversion context.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
Returns a concise summary of the conversion failure.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited