Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch all Java errors to avoid Android native app crashes #356

Merged
merged 1 commit into from
Apr 10, 2021

Conversation

steven-sh
Copy link
Contributor

It looks like there was a previous attempt at a catch-all for exceptions, however the try/catch blocks were outside the threads being created so the only call being caught was the call to start the thread. If an exception happened inside the thread while it was running, it would be uncaught and cause an app crash.

To fix the error catching I did the following:

  • Added try/catch blocks to any react method that didn't already have one
  • Added try/catch blocks to the code inside the thread runnables. If an error is caught it is logged to the console and the promise is rejected.
  • Changed the existing catch blocks to catch Throwable rather than Exception. Since both Error and Exception extend throwable (and all Errors are unchecked) this allows us to catch anything that could cause a native crash.

It might be worth removing the original try/catch blocks (outside the threads) to simplify the code since they aren't really catching much - what do you think?

Wrap all react methods in try/catch blocks, and reject the promise and log the stacktrace if any error is encountered.
@steven-sh steven-sh marked this pull request as ready for review March 28, 2021 10:23
@steven-sh steven-sh changed the title Fixes #352 Tach all Java errors to avoid Android native app crashes Mar 28, 2021
@steven-sh steven-sh changed the title Tach all Java errors to avoid Android native app crashes Catch all Java errors to avoid Android native app crashes Mar 28, 2021
Copy link
Collaborator

@MoOx MoOx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I am ok to remove try/catch that don't make sense.
@wmcmahan what do you think?

@wmcmahan
Copy link
Owner

wmcmahan commented Apr 6, 2021

I agree. These changes look good, maybe worth a separate PR for cleaning up old try blocka, since these changes are nice and succinct. Thanks again for the help!

@wmcmahan wmcmahan merged commit a3e15e1 into wmcmahan:master Apr 10, 2021
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.

4 participants