wrap function

void wrap(
  1. String methodName,
  2. InternalLogger logger,
  3. Map<String, Object?>? attributes,
  4. WrappedCall<void> call,
)

Wraps a call to a platform channel with common error handling and telemetry.

Implementation

void wrap(
  String methodName,
  InternalLogger logger,
  Map<String, Object?>? attributes,
  WrappedCall<void> call,
) {
  try {
    var result = call();
    if (result is Future) {
      result.catchError((dynamic e, StackTrace st) {
        _handleError(e, st, methodName, logger, attributes);
      }, test: _willHandleError);
    }
  } catch (e, st) {
    if (!_handleError(e, st, methodName, logger, attributes)) {
      rethrow;
    }
  }
}