Skip to content

Instantly share code, notes, and snippets.

@jrlemieux
Created January 24, 2012 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrlemieux/1672660 to your computer and use it in GitHub Desktop.
Save jrlemieux/1672660 to your computer and use it in GitHub Desktop.
CompositeThrowable inconsistency?
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, _))))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment