I am trying to follow the sparkjava exception handling example located here, without success: http://sparkjava.com/documentation.html#exception-mapping. It appears the code they posted isn't quite right? I was able to fix one of the posted methods so that it compiles. The method on the documentation page which doesn't compile was:
get("/throwexception", (request, response) -> {
throw new NotFoundException();
});
I changed to this code and it compiles:
get(new Route("/throwexception") {
@Override
public Object handle(Request request, Response response) {
throw new IllegalArgumentException();
}
});
However, I am unable to get this method to compile. What is wrong? I am using java 8 and IntelliJ community edition 15.0.2 to compile. My java module is set to language level 8. Here is the suspect method:
exception(Exception.class, (e, request, response) -> {
//TODO: implement this after it compiles.
});
Here is the error I get from the compiler:
Error:(83, 9) java: cannot find symbol
symbol: method exception(java.lang.Class<java.lang.Exception>,(e,request[...]->{ })
location: class org.me.JournalController
To confirm that I really am using java 8, this example using a lambda expression does compile:
public class Lambdas {
public static void main(String[] args) throws Exception {
new Lambdas().start();
Thread.sleep(1000);
}
public void start(){
Interface f = () -> System.out.println("test");
}
}