Scala on Android with scala.concurrent.Future not reporting system err / out exception

We are creating an Android application with Scala 2.11. We use scala.concurrent.Future for asynchronous background tasks. The problem is that we do not see any exceptions in logcat if the exceptions are excluded from the Future block.

We have already created an execution context with our own reporter:

lazy val reporter: (Throwable => Unit) = {
    t =>
      t.printStackTrace()
  }

  implicit lazy val exec = ExecutionContext.fromExecutor(
    new ThreadPoolExecutor(10, 100, 5, TimeUnit.MINUTES,
      new LinkedBlockingQueue[Runnable]), reporter)

Even if I set a breakpoint inside the reporter, the debugger never stops here, even if I force throwing insde exceptions into the Future block {...}. What are we doing wrong

+1
source share
1 answer

, , Future . - , (, , ), :

scala> Future { 10 / 0 }
res21: scala.concurrent.Future[Int] = scala.concurrent.impl.Promise$DefaultPromise@24f3ffd

, . , , .. onComplete onFailure, :

scala> res21.onFailure { case error => println(s"Error: ${ error.getMessage }") }
Error: / by zero

.

+3

Source: https://habr.com/ru/post/1546307/


All Articles