summaryrefslogtreecommitdiff
path: root/test/files/neg/catch-all.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-06-16 23:35:06 +0200
committerJason Zaugg <jzaugg@gmail.com>2012-06-19 21:35:28 +0200
commit7d8527b40a3bd6d93cf155b39ee50577751f3e91 (patch)
treed02e00108568bfc8236782962f15ccc30b50446c /test/files/neg/catch-all.scala
parent277dc7cf43566f8294bde4143107d9bfaa59e8e3 (diff)
downloadscala-7d8527b40a3bd6d93cf155b39ee50577751f3e91.tar.gz
scala-7d8527b40a3bd6d93cf155b39ee50577751f3e91.tar.bz2
scala-7d8527b40a3bd6d93cf155b39ee50577751f3e91.zip
SI-2807 Resurrect and refine the promiscuous catch warning.
The previous incarnation didn't survive 4fb3473. This version can be cleared by using a typed pattern: `catch { case _: Throwable => }`. This is motivated by the recent appearance of such a catch in `util.Try`, and by battle scars left by one too many processes bravely but stupidly catching and logging OutOfMemoryErrors. -Y status has been skipped: this warning is enabled by default and can only be silenced with use of a typed pattern.
Diffstat (limited to 'test/files/neg/catch-all.scala')
-rw-r--r--test/files/neg/catch-all.scala19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/files/neg/catch-all.scala b/test/files/neg/catch-all.scala
new file mode 100644
index 0000000000..35a6d7af91
--- /dev/null
+++ b/test/files/neg/catch-all.scala
@@ -0,0 +1,19 @@
+object CatchAll {
+ try { "warn" } catch { case _ => }
+
+ try { "warn" } catch { case x => }
+
+ try { "warn" } catch { case _: RuntimeException => ; case x => }
+
+ try { "okay" } catch { case _: Throwable => }
+
+ try { "okay" } catch { case _: Exception => }
+
+ try { "okay" } catch { case okay: Throwable => }
+
+ try { "okay" } catch { case okay: Exception => }
+
+ try { "okay" } catch { case _ if "".isEmpty => }
+
+ "okay" match { case _ => "" }
+}