captureException method
Future<SentryId>
captureException(
- dynamic throwable, {
- dynamic stackTrace,
- dynamic hint,
- 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 = await _cloneAndRunWithScope(item.scope, withScope);
try {
var event = SentryEvent(
throwable: throwable,
timestamp: _options.clock(),
);
if (_options.isTracingEnabled()) {
event = _assignTraceContext(event);
}
sentryId = await item.client.captureEvent(
event,
stackTrace: stackTrace,
scope: scope,
hint: hint,
);
} catch (exception, stackTrace) {
_options.logger(
SentryLevel.error,
'Error while capturing exception',
exception: exception,
stackTrace: stackTrace,
);
} finally {
_lastEventId = sentryId;
}
}
return sentryId;
}