File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1+ import java .io .IOException
2+ import java .lang .NullPointerException
3+ import java .lang .IllegalArgumentException
4+
5+ object IAE {
6+ def unapply (e : Exception ): Option [String ] =
7+ if (e.isInstanceOf [IllegalArgumentException ]) Some (e.getMessage)
8+ else None
9+ }
10+
11+ object EX extends Exception
12+
13+ trait ExceptionTrait extends Exception
14+
15+ object Test {
16+ def main (args : Array [String ]): Unit = {
17+ var a : Int = 1
18+ try {
19+ throw new IllegalArgumentException ()
20+ } catch {
21+ case e : IOException if e.getMessage == null =>
22+ case e : NullPointerException =>
23+ case e : IndexOutOfBoundsException =>
24+ case _ : NoSuchElementException =>
25+ case _ : ExceptionTrait =>
26+ case _ : NoSuchElementException if a <= 1 =>
27+ case _ : NullPointerException | _:IOException =>
28+ case `a` => // error: cannot compare
29+ case EX =>
30+ case IAE (msg) =>
31+ case e : IllegalArgumentException =>
32+ }
33+ }
34+ }
Original file line number Diff line number Diff line change @@ -25,7 +25,6 @@ object Test {
2525 case _ : ExceptionTrait =>
2626 case _ : NoSuchElementException if a <= 1 =>
2727 case _ : NullPointerException | _:IOException =>
28- case `a` => // This case should probably emmit an error
2928 case e : Int => // error
3029 case EX =>
3130 case IAE (msg) =>
You can’t perform that action at this time.
0 commit comments