Reputation: 676
I run my java application on a MacOS 10.9.5 (Mavericks) with JavaSE 1.7.0_60 installed.
I want to use the multi-catch statement for catch some exceptions...
But When I try to run my app I got an error like this:
Internal Server Error (500) for request GET /tresTest/authenticate
Compilation error (In /app/controllers/TestBoxController.java around line 57)
The file /app/controllers/TestBoxController.java could not be compiled. Error raised is : Syntax error on tokens, delete these tokens
The reason of this error is this line of code:
try {
class.someMethodTrowingException();
} catch (MyExceptionNo1 | MyExceptionNo2 | MyExceptionNo3 e) {
doSomethigUseful();
}
If type java -version
on my console, i got this result:
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
I can't understand why I got this behavior. Multi-catch statement is allow in Java7, right?
I know that if I use catch in this way everything go right
try {
class.someMethodTrowingException();
} catch (MyExceptionNo1 e1) {
doSomethigUseful();
} catch (MyExceptionNo2 e2) {
doSomethigUseful();
} catch (MyExceptionNo3 e3) {
doSomethigUseful();
}
But my goal it to use the multi-catch statement like catch (MyExceptionNo1 | MyExceptionNo2 | MyExceptionNo3 e) {...}
Check this out: http://docs.oracle.com/javase/7/docs/technotes/guides/language/catch-multiple.html
Found out the problem. It's Play that use 1.6 Java compatibility even if I told to its to not use it. Don't understand yet why, and don't understand yet how to sole, but at least I understand where problem is... :)
Upvotes: 0
Views: 931
Reputation: 201
Add the below plugin in maven to compile it using Java version 1.7
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Upvotes: 0