public
Created

CompositeThrowable inconsistency?

  • Download Gist
composite.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
object Test {
 
def main(args: Array[String]) {
 
def process(animal: String, n: Int) = {
if (n % 13 == 0 && n > 0)
throw new Exception("My " + animal + " hates number " + n)
n
}
 
def show(what: String, messages: Seq[String]) {
println(what)
messages.foreach(m => println(" - " + m))
}
 
def test(u: () => Any) {
println
try {
u()
} catch {
case e: scala.collection.parallel.CompositeThrowable =>
show("Composite", e.throwables.toList.map(t => t.getClass.getName + ": " + t.getMessage))
case e =>
show("Simple", Seq(e.getMessage))
}
}
 
test(() => (0 until 20).map(process("hamster", _)))
test(() => (0 until 20).par.map(process("hamster", _)))
 
test(() => (0 until 50).map(process("rabbit", _)))
test(() => (0 until 50).par.map(process("rabbit", _)))
 
test(() => List("cat", "dog").map(a => (0 until 50).map(process(a, _))))
test(() => List("cat", "dog").map(a => (0 until 50).par.map(process(a, _))))
test(() => List("cat", "dog").par.map(a => (0 until 50).map(process(a, _))))
test(() => List("cat", "dog").par.map(a => (0 until 50).par.map(process(a, _))))
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.