From 4831ef51a7b46b6ba4b8e120d5ff2ba66d8f7bac Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Thu, 6 Sep 2012 19:11:22 -0400 Subject: Fix for SI-6333 - Try throws from combinators. * Added more comprehensive tests to Try. * Delineated what methods do and don't catch exceptions in docs. * Fixed combinator methods that should catch exceptions. --- test/files/run/t6333.scala | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/files/run/t6333.scala (limited to 'test/files/run') diff --git a/test/files/run/t6333.scala b/test/files/run/t6333.scala new file mode 100644 index 0000000000..266d95ce69 --- /dev/null +++ b/test/files/run/t6333.scala @@ -0,0 +1,29 @@ +object Test extends App { + import util.Try + + val a = "apple" + def fail: String = throw new Exception("Fail!") + def argh: Try[String] = throw new Exception("Argh!") + + // No throw tests + def tryMethods(expr: => String): Unit = { + Try(expr) orElse argh + Try(expr).transform(_ => argh, _ => argh) + Try(expr).recoverWith { case e if (a == fail) => Try(a) } + Try(expr).recoverWith { case _ => argh } + Try(expr).getOrElse(a) + // TODO - Fail getOrElse? + Try(expr) orElse argh + Try(expr) orElse Try(a) + Try(expr) map (_ => fail) + Try(expr) map (_ => a) + Try(expr) flatMap (_ => argh) + Try(expr) flatMap (_ => Try(a)) + Try(expr) filter (_ => throw new Exception("O NOES")) + Try(expr) filter (_ => true) + Try(expr) recover { case _ => fail } + Try(expr).failed + } + tryMethods(a) + tryMethods(fail) +} -- cgit v1.2.3