invoke<T> static method

Object? invoke<T>(
  1. PairedConverter converter,
  2. Object? source,
  3. Class sourceType,
  4. Class targetType,
)

Invokes the provided converter with the given source, sourceType, and targetType descriptors, handling conversion failures appropriately.

If a ConversionFailedException is thrown during conversion, it is rethrown directly. For any other Exception, a new ConversionFailedException is thrown with context.

🔧 Example

final result = ConversionUtils.invokeConverter(
  myConverter,
  '123',
  Class.of(String),
  Class.of(int),
);

Implementation

static Object? invoke<T>(PairedConverter converter, Object? source, Class sourceType, Class targetType) {
		try {
			return converter.convert<T>(source, sourceType, targetType);
		} on ConversionFailedException catch (_) {
			rethrow;
		} on ConversionException catch (_) {
			rethrow;
		} on Exception catch (ex) {
			throw ConversionFailedException(sourceType: sourceType, targetType: targetType, value: source, point: ex);
		} on Error catch (ex) {
    throw ConversionFailedException(sourceType: sourceType, targetType: targetType, value: source, point: ex);
  }
	}