Skip to content

Commit

Permalink
Merge pull request scala#2563 from soc/SI-7474
Browse files Browse the repository at this point in the history
SI-7474 Parallel collections: End the exception handling madness
  • Loading branch information
JamesIry committed May 28, 2013
2 parents 96e67c2 + bcbe38d commit b88801f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
12 changes: 7 additions & 5 deletions src/library/scala/collection/parallel/Tasks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/library/scala/collection/parallel/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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")
)
Expand Down
2 changes: 1 addition & 1 deletion test/files/run/t5375.check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Composite throwable
Runtime exception
23 changes: 6 additions & 17 deletions test/files/run/t5375.scala
Original file line number Diff line number Diff line change
@@ -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.