Guard div_zero button against fatal ArithmeticException - #249
Open
sentry[bot] wants to merge 1 commit into
Open
Conversation
The div_zero button's click listener in MainActivity executed a hardcoded `int t = 5 / 0;` with no runtime protection, so tapping the "ArithmeticException" button threw an unhandled ArithmeticException and crashed the app fatally. Wrap the division in a try/catch and report it through Sentry.captureException() so the demo still produces a Sentry event without killing the process. Fixes [ANDROID-M0](https://demo.sentry.io/issues/7653043052/)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #249 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 16 16
Lines 883 887 +4
Branches 67 67
=====================================
- Misses 883 887 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes ANDROID-M0
Problem
Tapping the
div_zero("ArithmeticException") button inMainActivityexecuted a hardcodedint t = 5 / 0;inside the click listener (MainActivity.java:53). There was notry/catcharound it, so theArithmeticExceptionpropagated out oflambda$onCreate$0unhandled and the app crashed fatally.Fix
The division is kept so the demo still exercises the error path, but it is now wrapped in a
try/catch (ArithmeticException e)that reports the error viaSentry.captureException(e)— matching the pattern already used by thehandled_exceptionbutton in the same activity.The divisor is held in a local variable rather than a
0literal sojavacdoes not emit a division-by-zero warning; the runtime behaviour (ArithmeticException: / by zero) is identical.The existing breadcrumb and attachment setup is unchanged, so the Sentry event carries the same context as before — it now arrives as a handled error instead of a fatal crash. The surrounding comment was updated from "Unhandled" to "Handled" to reflect the new behaviour.
Verification
MainActivity.javahas no syntax errors (javacreports only expected missing Android/Sentry/Gradle-generated symbols, as no Android SDK is available in this environment).ArithmeticException: / by zerois thrown, caught, and routed to the capture path with no fatal propagation.