Search in sources :

Example 6 with JPLException

use of org.jpl7.JPLException in project packages-jpl by SWI-Prolog.

the class TestJUnit method testOpenGetClose2.

public void testOpenGetClose2() {
    // we're not going to open this...
    Query q = new Query("dummy");
    try {
        // should throw exception (query not open)
        q.getSolution();
        // shouldn't get
        fail("getSolution() succeeds on unopened Query");
    // to here
    } catch (JPLException e) {
        // expected exception class
        if (e.getMessage().endsWith("Query is not open")) {
        // OK: an appropriate exception was thrown
        } else {
            fail("jpl.Query#getSolution() threw wrong JPLException: " + e);
        }
    } catch (Exception e) {
        fail("jpl.Query#getSolution() threw wrong exception class: " + e);
    }
}
Also used : Query(org.jpl7.Query) JPLException(org.jpl7.JPLException) PrologException(org.jpl7.PrologException) JPLException(org.jpl7.JPLException)

Example 7 with JPLException

use of org.jpl7.JPLException in project packages-jpl by SWI-Prolog.

the class TestJUnit method testGetSolution2.

public void testGetSolution2() {
    // this query has no solutions
    Query q = new Query("fail");
    // this opens the query
    q.open();
    // this finds no solution, and closes the query
    q.getSolution();
    try {
        // this call is invalid, as the query is closed
        q.getSolution();
        // shouldn't get to here
        fail("jpl.Query#getSolution() shoulda thrown JPLException");
    } catch (JPLException e) {
        // in detail?
        if (e.getMessage().endsWith("Query is not open")) {
        // ...which
        // should throw
        // a
        // JPLException
        // like this
        // OK: an appropriate exception was thrown
        } else {
            fail("jpl.Query#getSolution() threw incorrect JPLException: " + e);
        }
    } catch (Exception e) {
        fail("jpl.Query#getSolution() threw wrong class of exception: " + e);
    }
}
Also used : Query(org.jpl7.Query) JPLException(org.jpl7.JPLException) PrologException(org.jpl7.PrologException) JPLException(org.jpl7.JPLException)

Aggregations

JPLException (org.jpl7.JPLException)4 PrologException (org.jpl7.PrologException)4 Query (org.jpl7.Query)2 Term (org.jpl7.Term)2 IntHolder (org.jpl7.fli.IntHolder)2 BigInteger (java.math.BigInteger)1 Atom (org.jpl7.Atom)1 Compound (org.jpl7.Compound)1 DoubleHolder (org.jpl7.fli.DoubleHolder)1 Int64Holder (org.jpl7.fli.Int64Holder)1 ObjectHolder (org.jpl7.fli.ObjectHolder)1 StringHolder (org.jpl7.fli.StringHolder)1 org.jpl7.fli.qid_t (org.jpl7.fli.qid_t)1 org.jpl7.fli.term_t (org.jpl7.fli.term_t)1