summaryrefslogtreecommitdiff
path: root/test/files/run/t6333.scala
diff options
context:
space:
mode:
authorJosh Suereth <joshua.suereth@gmail.com>2012-09-06 19:11:22 -0400
committerJosh Suereth <joshua.suereth@gmail.com>2012-09-07 08:17:52 -0400
commit4831ef51a7b46b6ba4b8e120d5ff2ba66d8f7bac (patch)
treeb0060b0d666b43df99d06e67e41e95e25aec7118 /test/files/run/t6333.scala
parentb7e08723d142c8227181eed283e7c982f449425a (diff)
downloadscala-4831ef51a7b46b6ba4b8e120d5ff2ba66d8f7bac.tar.gz
scala-4831ef51a7b46b6ba4b8e120d5ff2ba66d8f7bac.tar.bz2
scala-4831ef51a7b46b6ba4b8e120d5ff2ba66d8f7bac.zip
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.
Diffstat (limited to 'test/files/run/t6333.scala')
-rw-r--r--test/files/run/t6333.scala29
1 files changed, 29 insertions, 0 deletions
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)
+}