Skip to content

Exceptions thrown when calling Sentry.captureException in Flutter app #3349

@GowthamanRavichandran3

Description

@GowthamanRavichandran3

Platform

Flutter Mobile Android, Flutter Mobile iOS

Obfuscation

Disabled

Debug Info

Disabled

Doctor

[✓] Flutter (Channel stable, 3.35.4, on macOS 15.4.1 24E263 darwin-arm64, locale en-IN) [991ms]
• Flutter version 3.35.4 on channel stable at /Users/gowthamanravichandran/Documents/flutter sdk/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision d693b4b9db (9 weeks ago), 2025-09-16 14:27:41 +0000
• Engine revision c298091351
• Dart version 3.9.2
• DevTools version 2.48.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations,
enable-lldb-debugging

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [5.1s]
• Android SDK at /Users/gowthamanravichandran/Library/Android/sdk
• Emulator version 36.2.11.0 (build_id 14212360) (CL:N/A)
• Platform android-36, build-tools 35.0.0
• Java binary at: /opt/homebrew/Cellar/openjdk@17/17.0.17/libexec/openjdk.jdk/Contents/Home/bin/java
This JDK is specified by the JAVA_HOME environment variable.
To manually set the JDK path, use: flutter config --jdk-dir="path/to/jdk".
• Java version OpenJDK Runtime Environment Homebrew (build 17.0.17+0)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 16.3) [4.8s]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16E140
• CocoaPods version 1.16.2

[✓] Chrome - develop for the web [27ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed) [26ms]
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/to/macos-android-setup for detailed instructions).

[✓] VS Code (version 1.105.1) [26ms]
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.122.0

[✓] Connected device (4 available) [9.4s]
• IPAD-31422 (mobile) • 00008103-0014504102D3001E • ios • iOS 26.0 23A341
• iPhone 15 (mobile) • 9F36B7AA-0183-40F3-A69F-466C1664FB98 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 15.4.1 24E263 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 142.0.7444.176

[✓] Network resources [807ms]
• All expected network resources are available.

! Doctor found issues in 2 categories.

Version

9.0.0

Steps to Reproduce

I am using the following code in my Flutter app to capture exceptions and send them to Sentry:
await Sentry.captureException(exception, stackTrace: stackTrace);

However, when this line executes, I encounter the following exceptions in my app:

  1. TimeoutException after 0:00:03.000000: Future not completed
  2. 429: Too Many Requests
  3. HandshakeException: Connection terminated during handshake

What I Tried

  1. Using try-catch block:
try {
  await Sentry.captureException(
    exception,
    stackTrace: stackTrace,
  );
} catch (e, sentryErrorStack) {
  debugPrint('Failed to report to Sentry: $e');
  debugPrint('Sentry error stack: $sentryErrorStack');
}

But the exceptions are not caught in the catch block.

  1. Using catchError:
await Sentry.captureException(error, stackTrace: trace).catchError((e, st) {
  return const SentryId.empty();
});

Even with this, the exceptions are still thrown and logged in Sentry.

Expected Result

I want to prevent these network-related exceptions (TimeoutException, 429 Too Many Requests, HandshakeException) from being logged in Sentry or at least handle them gracefully without crashing the app.

Actual Result

The exceptions are thrown and logged in Sentry despite using try-catch and catchError.

Are you willing to submit a PR?

None

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Waiting for: Community

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions