captureException method

Future<SentryId> captureException(
  1. dynamic throwable, {
  2. dynamic stackTrace,
  3. dynamic hint,
  4. ScopeCallback? withScope,
})

Captures the exception

Implementation

Future<SentryId> captureException(
  dynamic throwable, {
  dynamic stackTrace,
  dynamic hint,
  ScopeCallback? withScope,
}) async {
  var sentryId = SentryId.empty();

  if (!_isEnabled) {
    _options.logger(
      SentryLevel.warning,
      "Instance is disabled and this 'captureException' call is a no-op.",
    );
  } else if (throwable == null) {
    _options.logger(
      SentryLevel.warning,
      'captureException called with null parameter.',
    );
  } else {
    final item = _peek();
    final scope = _cloneAndRunWithScope(item.scope, withScope);

    try {
      sentryId = await item.client.captureException(
        throwable,
        stackTrace: stackTrace,
        scope: scope,
        hint: hint,
      );
    } catch (err) {
      _options.logger(
        SentryLevel.error,
        'Error while capturing exception : $throwable',
      );
    } finally {
      _lastEventId = sentryId;
    }
  }

  return sentryId;
}