safeExecute static method

void safeExecute(
  1. void operation(), {
  2. bool silenceStreamErrors = true,
})

Wraps a function execution with safe error handling

Useful for operations that might throw but shouldn't crash the app.

Implementation

static void safeExecute(
  void Function() operation, {
  bool silenceStreamErrors = true,
}) {
  try {
    operation();
  } catch (error, stackTrace) {
    if (silenceStreamErrors && isStreamClosureError(error)) {
      return;
    }
    NewrelicMobile.instance.recordError(error, stackTrace);
    rethrow;
  }
}