Skip to content

Commit b88801f

Browse files
committed
Merge pull request scala#2563 from soc/SI-7474
SI-7474 Parallel collections: End the exception handling madness
2 parents 96e67c2 + bcbe38d commit b88801f

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

src/library/scala/collection/parallel/Tasks.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ trait Task[R, +Tp] {
7272
}
7373

7474
private[parallel] def mergeThrowables(that: Task[_, _]) {
75-
if (this.throwable != null && that.throwable != null) {
76-
// merge exceptions, since there were multiple exceptions
77-
this.throwable = this.throwable alongWith that.throwable
78-
} else if (that.throwable != null) this.throwable = that.throwable
79-
else this.throwable = this.throwable
75+
// TODO: As soon as we target Java >= 7, use Throwable#addSuppressed
76+
// to pass additional Throwables to the caller, e. g.
77+
// if (this.throwable != null && that.throwable != null)
78+
// this.throwable.addSuppressed(that.throwable)
79+
// For now, we just use whatever Throwable comes across “first”.
80+
if (this.throwable == null && that.throwable != null)
81+
this.throwable = that.throwable
8082
}
8183

8284
// override in concrete task implementations to signal abort to other tasks

src/library/scala/collection/parallel/package.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ package parallel {
114114
def toParArray: ParArray[T]
115115
}
116116

117+
@deprecated("This trait will be removed.", "2.11.0")
117118
trait ThrowableOps {
119+
@deprecated("This method will be removed.", "2.11.0")
118120
def alongWith(that: Throwable): Throwable
119121
}
120122

@@ -133,9 +135,8 @@ package parallel {
133135
}
134136

135137
/** Composite throwable - thrown when multiple exceptions are thrown at the same time. */
136-
final case class CompositeThrowable(
137-
throwables: Set[Throwable]
138-
) extends Exception(
138+
@deprecated("This class will be removed.", "2.11.0")
139+
final case class CompositeThrowable(throwables: Set[Throwable]) extends Exception(
139140
"Multiple exceptions thrown during a parallel computation: " +
140141
throwables.map(t => t + "\n" + t.getStackTrace.take(10).++("...").mkString("\n")).mkString("\n\n")
141142
)

test/files/run/t5375.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Composite throwable
1+
Runtime exception

test/files/run/t5375.scala

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
2-
3-
4-
import collection.parallel.CompositeThrowable
5-
6-
7-
8-
object Test {
9-
10-
def main(args: Array[String]) {
11-
val foos = (1 to 1000).toSeq
12-
try {
13-
foos.par.map(i => if (i % 37 == 0) sys.error("i div 37") else i)
14-
} catch {
15-
case CompositeThrowable(thr) => println("Composite throwable")
16-
}
1+
object Test extends App {
2+
val foos = (1 to 1000).toSeq
3+
try
4+
foos.par.map(i => if (i % 37 == 0) sys.error("i div 37") else i)
5+
catch {
6+
case ex: RuntimeException => println("Runtime exception")
177
}
18-
198
}

0 commit comments

Comments
 (0)