When I use JPL (from JavaSE 1.8), Prolog (SWI-Prolog version 8.2.2) can return an error message without throwing an exception. E.g. when using consult and the file has errors:
import org.jpl7.Query;
public class Test {
public static void main(String[] args) {
try {
String t1 = "consult('test.pl')";
Query q1 = new Query(t1);
q1.hasNext();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I get the output at the console:
ERROR: test.pl:1:23: Syntax error: Unexpected end of file
But no exception is thrown. Therefore my Java program cannot know that the consulted file has errors. The file test.pl that I used in this simple example only contains a simple predicate with a syntactical error:
brother(mike, stella)..
What can I do so that my Java program can catch this error? A post with a similar title doesn't seem to resolve this issue...
Maybe I can use a syntactical checking method either from JPL, or another source, any concrete ideas?