Permalink
Browse files

Merge pull request #2563 from soc/SI-7474

SI-7474 Parallel collections: End the exception handling madness
  • Loading branch information...
2 parents 96e67c2 + bcbe38d commit b88801fac7cb1d7d38d4b3cca4aab4603c48527e @JamesIry JamesIry committed May 28, 2013
@@ -72,11 +72,13 @@ trait Task[R, +Tp] {
}
private[parallel] def mergeThrowables(that: Task[_, _]) {
- if (this.throwable != null && that.throwable != null) {
- // merge exceptions, since there were multiple exceptions
- this.throwable = this.throwable alongWith that.throwable
- } else if (that.throwable != null) this.throwable = that.throwable
- else this.throwable = this.throwable
+ // TODO: As soon as we target Java >= 7, use Throwable#addSuppressed
+ // to pass additional Throwables to the caller, e. g.
+ // if (this.throwable != null && that.throwable != null)
+ // this.throwable.addSuppressed(that.throwable)
+ // For now, we just use whatever Throwable comes across “first”.
+ if (this.throwable == null && that.throwable != null)
+ this.throwable = that.throwable
}
// override in concrete task implementations to signal abort to other tasks
@@ -114,7 +114,9 @@ package parallel {
def toParArray: ParArray[T]
}
+ @deprecated("This trait will be removed.", "2.11.0")
trait ThrowableOps {
+ @deprecated("This method will be removed.", "2.11.0")
def alongWith(that: Throwable): Throwable
}
@@ -133,9 +135,8 @@ package parallel {
}
/** Composite throwable - thrown when multiple exceptions are thrown at the same time. */
- final case class CompositeThrowable(
- throwables: Set[Throwable]
- ) extends Exception(
+ @deprecated("This class will be removed.", "2.11.0")
+ final case class CompositeThrowable(throwables: Set[Throwable]) extends Exception(
"Multiple exceptions thrown during a parallel computation: " +
throwables.map(t => t + "\n" + t.getStackTrace.take(10).++("...").mkString("\n")).mkString("\n\n")
)
@@ -1 +1 @@
-Composite throwable
+Runtime exception
View
@@ -1,19 +1,8 @@
-
-
-
-import collection.parallel.CompositeThrowable
-
-
-
-object Test {
-
- def main(args: Array[String]) {
- val foos = (1 to 1000).toSeq
- try {
- foos.par.map(i => if (i % 37 == 0) sys.error("i div 37") else i)
- } catch {
- case CompositeThrowable(thr) => println("Composite throwable")
- }
+object Test extends App {
+ val foos = (1 to 1000).toSeq
+ try
+ foos.par.map(i => if (i % 37 == 0) sys.error("i div 37") else i)
+ catch {
+ case ex: RuntimeException => println("Runtime exception")
}
-
}

0 comments on commit b88801f

Please sign in to comment.