parser<T> function

T parser<T>(
  1. T build(), {
  2. required Object? data,
})

Parser helper that catches model/JSON construction errors and throws a typed ParsingException (which extends your data exceptions).

Implementation

T parser<T>(T Function() build, {required Object? data}) {
  try {
    return build();
  } catch (e, s) {
    if (e is BaseException) rethrow;
    throw ParsingException(
      rawData: data,
      targetType: '$T',
      cause: e,
      stack: s,
    );
  }
}