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

PSA: Exceptions in Future are hidden #56

Open
Nutomic opened this issue Apr 23, 2015 · 2 comments
Open

PSA: Exceptions in Future are hidden #56

Nutomic opened this issue Apr 23, 2015 · 2 comments

Comments

@Nutomic
Copy link

Nutomic commented Apr 23, 2015

    Future {
      throw new Exception
    }

This code does nothing at all, the app doesn't force close, and the error isn't even logged. As a workaround, you can do this:

    Future {
      throw new Exception
    }.onFailure { case e =>
      Log.w(Tag, "Error in future", e)
    }

I don't know if this can by fixed by the gradle plugin, but if not, you should probably use the workaround in your code.

@stanch
Copy link

stanch commented May 27, 2015

I think you can use a custom ExecutionContext with an overridden reportFailure method, like so: https://github.com/macroid/macroid/blob/master/macroid-core/src/main/scala/macroid/UiThreading.scala#L9

@Mygod
Copy link

Mygod commented Dec 3, 2015

@stanch According to doc: Failed tasks should call reportFailure to let the ExecutionContext log the problem or whatever is appropriate for the implementation.

And as I've tested with the code below, method reportFailure was not called.

Future(throw new Exception("Test"))(customExecutionContext)

Here's another workaround.

Future(throw new Exception("Test")) onFailure {
  case exc: Exception => exc.printStackTrace()
}

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

No branches or pull requests

3 participants