From af8416bb7ff4d6816f416cd0671e26e2cdc653d7 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Fri, 13 Apr 2012 18:11:38 +0200 Subject: Adding NonFatal matching as to not catch anything that should terminate the JVM, also adding EX.reportFailure where it makes sense --- src/library/scala/concurrent/Future.scala | 11 ++++++----- src/library/scala/concurrent/impl/Future.scala | 12 ++++-------- src/library/scala/concurrent/impl/Promise.scala | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala index f331263d39..40acea91c9 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -18,6 +18,7 @@ import java.{ lang => jl } import java.util.concurrent.atomic.{ AtomicReferenceFieldUpdater, AtomicInteger, AtomicBoolean } import scala.concurrent.util.Duration +import scala.concurrent.impl.NonFatal import scala.Option import scala.annotation.tailrec @@ -203,7 +204,7 @@ trait Future[+T] extends Awaitable[T] { case Right(v) => try p success f(v) catch { - case t => p complete resolver(t) + case NonFatal(t) => p complete resolver(t) } } @@ -229,7 +230,7 @@ trait Future[+T] extends Awaitable[T] { case Right(v) => p success v } } catch { - case t: Throwable => p complete resolver(t) + case NonFatal(t) => p complete resolver(t) } } @@ -262,7 +263,7 @@ trait Future[+T] extends Awaitable[T] { if (pred(v)) p success v else p failure new NoSuchElementException("Future.filter predicate is not satisfied by: " + v) } catch { - case t: Throwable => p complete resolver(t) + case NonFatal(t) => p complete resolver(t) } } @@ -336,7 +337,7 @@ trait Future[+T] extends Awaitable[T] { onComplete { case Left(t) if pf isDefinedAt t => try { p success pf(t) } - catch { case t: Throwable => p complete resolver(t) } + catch { case NonFatal(t) => p complete resolver(t) } case otherwise => p complete otherwise } @@ -364,7 +365,7 @@ trait Future[+T] extends Awaitable[T] { try { p completeWith pf(t) } catch { - case t: Throwable => p complete resolver(t) + case NonFatal(t) => p complete resolver(t) } case otherwise => p complete otherwise } diff --git a/src/library/scala/concurrent/impl/Future.scala b/src/library/scala/concurrent/impl/Future.scala index 72ffa6a014..ca13981163 100644 --- a/src/library/scala/concurrent/impl/Future.scala +++ b/src/library/scala/concurrent/impl/Future.scala @@ -77,7 +77,9 @@ object Future { try { Right(body) } catch { - case e => scala.concurrent.resolver(e) + case NonFatal(e) => + executor.reportFailure(e) + scala.concurrent.resolver(e) } } } @@ -115,13 +117,7 @@ object Future { _taskStack set taskStack while (taskStack.nonEmpty) { val next = taskStack.pop() - try { - next.apply() - } catch { - case e => - // TODO catching all and continue isn't good for OOME - executor.reportFailure(e) - } + try next() catch { case NonFatal(e) => executor reportFailure e } } } finally { _taskStack.remove() diff --git a/src/library/scala/concurrent/impl/Promise.scala b/src/library/scala/concurrent/impl/Promise.scala index 140cfa93a0..1388c8b357 100644 --- a/src/library/scala/concurrent/impl/Promise.scala +++ b/src/library/scala/concurrent/impl/Promise.scala @@ -180,7 +180,7 @@ object Promise { try { func(result) } catch { - case /*NonFatal(*/e/*)*/ => executor.reportFailure(e) + case NonFatal(e) => executor reportFailure e } } } -- cgit v1.2.3