@@ -349,24 +349,10 @@ handled, the `foreach` callback can be used:
349349 for (post <- posts) println(post)
350350 }
351351
352- To handle failed results, the ` foreach ` callback can be used on the
353- ` Future[Throwable] ` obtained via the ` failed ` projection (which is
354- explained [ below] ( #projections ) ):
355-
356- val f: Future[List[String]] = Future {
357- session.getRecentPosts
358- }
359-
360- f.failed foreach { t =>
361- println("An error has occured: " + t.getMessage)
362- }
363-
364- f foreach { posts =>
365- for (post <- posts) println(post)
366- }
367-
368- The ` failed.foreach ` callback is only executed if the future fails, that
369- is, if the original ` Future ` contains an exception.
352+ ` Future ` s provide a clean way of handling only failed results using
353+ the ` failed ` projection which converts a ` Failure[Throwable] ` to a
354+ ` Success[Throwable] ` . An example of doing this is provided in the
355+ section below on [ projections] ( #projections ) .
370356
371357Coming back to the previous example with searching for the first
372358occurrence of a keyword, you might want to print the position
@@ -710,12 +696,18 @@ which prints the exception to the screen:
710696 }
711697 for (exc <- f.failed) println(exc)
712698
699+ The for-comprehension in this example is translated to:
700+
701+ f.failed.foreach(exc => println(exc))
702+
703+ Because ` f ` is unsuccessful here, the closure is registered to
704+ the ` foreach ` callback on a newly-successful ` Future[Throwable] ` .
713705The following example does not print anything to the screen:
714706
715- val f = Future {
707+ val g = Future {
716708 4 / 2
717709 }
718- for (exc <- f .failed) println(exc)
710+ for (exc <- g .failed) println(exc)
719711
720712<!--
721713There is another projection called `timedout` which is specific to the
0 commit comments