Re: Are Errors in a Future body rethrown, as per the documentation?

Viktor Klang <[email protected]>
Newsgroups gmane.comp.lang.scala
Message-ID <CANPzfU-AWdabKWZGQYCOoKXF4dtBX0QzBour0rzm8bGFCSB3VQ@mail.gmail.com>
Andrew,

Indeed, also see revisions to NonFatal.

-- 
Cheers,
√
On 14 Jul 2015 00:17, "Andrew Phillips" <[email protected]> wrote:

> Hi Viktor
>
> > See the revision history / Issues for details.
>
> Thanks for the hint. The last change related to this seems to have
> been SI-7029 ("Fork join execution context loses fatal exceptions") [1],
> which added code to pass any exceptions caught to the fork-join pool
> thread's uncaught exception handler [2]. The above example is not related
> to the fork-join executor, however.
>
> The discussion in the issue has hopefully put me on the right track,
> though: what seems to be the case is that only *fatal* exceptions (as
> determined by NonFatal [3]) are re-thrown...and this includes
> ControlThrowable and InterruptedException, but *not* Error.
>
> Tweaking my original example to use InterruptedException gives the
> desired result:
>
> scala> Future { throw new InterruptedException("bang!") }.value
> DEBUG: running
> scala.concurrent.impl.Future$PromiseCompletingRunnable@7e6ce0a3
> java.lang.InterruptedException: bang!
>   at $anonfun$1.apply(<console>:12)
>   at $anonfun$1.apply(<console>:12)
>   at
> scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future
> .scala:24)
>   at
> scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
>
>   at SameThreadExecutionContext$.execute(<console>:13)
>   at scala.concurrent.impl.Future$.apply(Future.scala:31)
>   at scala.concurrent.Future$.apply(Future.scala:492)
>   ... 33 elided
>
>
> See https://github.com/scala/scala.github.com/pull/434
>
> Regards
>
> ap
>
> [1] https://issues.scala-lang.org/browse/SI-7029
> [2]
> https://github.com/scala/scala/commit/3f78bee128bd6a478bef6a66c5574f77a2d6dd74
> [3]
> https://github.com/scala/scala/blob/2.11.x/src/library/scala/util/control/NonFatal.scala#L37
>
> On Monday, July 13, 2015 at 5:05:12 PM UTC-4, √iktor Klang wrote:
>>
>> Hi Andrew,
>>
>> I think that behaviour was changed later on.
>> See the revision history / Issues for details.
>>
>> On Mon, Jul 13, 2015 at 10:09 PM, Andrew Phillips <[email protected]>
>> wrote:
>>
>>> Hi all
>>>
>>> With regard to the handling of Errors, the "Futures and Promises"
>>> documentation [1] states:
>>>
>>> ExecutionException - stored when the computation fails due to an
>>>> unhandled InterruptedException, Error or a
>>>> scala.util.control.ControlThrowable. In this case the
>>>> ExecutionException has the unhandled exception as its cause. *These
>>>> exceptions are rethrown in the thread executing the failed asynchronous
>>>> computation.*
>>>
>>>
>>> Is this latter statement true in general, e.g. also if you supply your
>>> own ExecutionContext? Or does it depend on the ExecutionContext
>>> implementation?
>>>
>>> In this example at least, nothing seems to be rethrown (or passed to
>>> reportFailure, for that matter):
>>>
>>> Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java
>>> 1.7.0_40).
>>>
>>>
>>> import scala.concurrent.Future
>>> import scala.concurrent.ExecutionContext
>>> import scala.util.{Failure, Success}
>>>
>>>
>>> implicit object SameThreadExecutionContext extends ExecutionContext {
>>>   override def execute(runnable: Runnable): Unit = {
>>>     println("DEBUG: running " + runnable)
>>>     runnable.run()
>>>   }
>>>   override def reportFailure(t: Throwable): Unit = ??? // never called?
>>> }
>>>
>>> scala> Future { throw new Error("bang!") }.value
>>> DEBUG: running
>>> scala.concurrent.impl.Future$PromiseCompletingRunnable@887b5d0
>>> res1: Option[scala.util.Try[Nothing]] =
>>> Some(Failure(java.util.concurrent.ExecutionException: Boxed Error))
>>>
>>>
>>> Am I missing something or misreading the docs here?
>>>
>>> Regards
>>>
>>> ap
>>>
>>> [1] http://docs.scala-lang.org/overviews/core/futures.html#exceptions
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "scala-language" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Cheers,
>> √
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "scala-language" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.