Add public API for checking unhandled exceptions#5177
Add public API for checking unhandled exceptions#5177jamescrosswell wants to merge 3 commits intomainfrom
Conversation
Adds two new public extension methods to SentryEvent: - IsFromUnhandledException(): Checks if event is from any unhandled exception - IsFromTerminalException(): Checks if event is from a terminal (crash-causing) exception This addresses the need to filter events based on whether they're unhandled/terminal, particularly useful in MAUI apps where users want to always capture terminal exceptions even if they match other filters (e.g., network timeouts). The implementation uses extension methods as suggested by @bruno-garcia, providing a clean public API without exposing internal methods. Both methods check Exception.Data and SentryExceptions for the handled/terminal flags. Fixes #2877 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5177 +/- ##
==========================================
+ Coverage 74.06% 74.07% +0.01%
==========================================
Files 501 502 +1
Lines 18113 18124 +11
Branches 3521 3527 +6
==========================================
+ Hits 13415 13425 +10
+ Misses 3838 3837 -1
- Partials 860 862 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 220411f. Configure here.
|
|
||
| // Check if any of the Sentry exceptions have an unhandled mechanism | ||
| return @event.SentryExceptions?.Any(e => e.Mechanism is { Handled: false }) ?? false; | ||
| } |
There was a problem hiding this comment.
Duplicated logic with existing internal methods risks divergence
Low Severity
IsFromUnhandledException() is an exact copy of the private HasUnhandledException() in SentryEvent.cs, and IsFromTerminalException() duplicates the complement of HasUnhandledNonTerminalException(). Both access only public properties (Exception, SentryExceptions), so the private methods could delegate to these new extension methods, eliminating the duplication and the risk of inconsistent future bug fixes.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 220411f. Configure here.


Summary
Adds two new public extension methods to
SentryEvent:IsFromUnhandledException(): Checks if the event is from any unhandled exceptionIsFromTerminalException(): Checks if the event is from a terminal (crash-causing) exceptionMotivation
Fixes #2877
Users need to filter events in callbacks like
BeforeSendbased on whether exceptions are unhandled/terminal. This is particularly useful in MAUI apps where you might want to filter out common exceptions (like network timeouts) but always capture them if they're terminal.Implementation
Following @bruno-garcia's feedback, this uses extension methods rather than making internal methods public. The methods check both
Exception.Dataflags andSentryExceptionsmechanism properties.Key differences:
Both are well-documented with XML docs and usage examples.
Test Plan
🤖 Generated with Claude Code