Skip to content

Guard div_zero button against fatal ArithmeticException - #249

Open
sentry[bot] wants to merge 1 commit into
mainfrom
claude/fix-arithmetic-exception-div-zero
Open

Guard div_zero button against fatal ArithmeticException#249
sentry[bot] wants to merge 1 commit into
mainfrom
claude/fix-arithmetic-exception-div-zero

Conversation

@sentry

@sentry sentry Bot commented Aug 6, 2026

Copy link
Copy Markdown

Fixes ANDROID-M0

Problem

Tapping the div_zero ("ArithmeticException") button in MainActivity executed a hardcoded int t = 5 / 0; inside the click listener (MainActivity.java:53). There was no try/catch around it, so the ArithmeticException propagated out of lambda$onCreate$0 unhandled 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 via Sentry.captureException(e) — matching the pattern already used by the handled_exception button in the same activity.

try {
    int divisor = 0;
    int t = 5 / divisor;
} catch (ArithmeticException e) {
    Sentry.captureException(e);
}

The divisor is held in a local variable rather than a 0 literal so javac does 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

  • Confirmed the modified MainActivity.java has no syntax errors (javac reports only expected missing Android/Sentry/Gradle-generated symbols, as no Android SDK is available in this environment).
  • Ran a standalone reproduction of the new listener body: the ArithmeticException: / by zero is thrown, caught, and routed to the capture path with no fatal propagation.

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/)
@sentry
sentry Bot requested a review from sdzhong as a code owner August 6, 2026 02:54
@sentry

sentry Bot commented Aug 6, 2026

Copy link
Copy Markdown
Author

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Android com.example.vu.android 24.12.26 (241226) release
Android com.example.vu.android 24.12.26 (241226) debug
Android com.example.vu.android 24.12.26 (241226) release

⚙️ android Build Distribution Settings

@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (2bef372) to head (dd2582e).

Files with missing lines Patch % Lines
...main/java/com/example/vu/android/MainActivity.java 0.00% 5 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant