/// <summary> /// Provide the next solution to the query. Prolog exceptions are mapped to C# exceptions. /// </summary> /// <returns>return true if successful and false if there are no (more) solutions.</returns> /// <remarks> /// <para>If the query is closed it will be opened. If the last solution was generated the query will be closed.</para> /// <para>If an exception is thrown while parsing (open) the query the _qid is set to zero.</para> /// </remarks> /// <exception cref="PlException">Is thrown if <see href="http://gollem.science.uva.nl/SWI-Prolog/Manual/foreigninclude.html#PL_next_solution()">SWI-Prolog Manual PL_next_solution()</see> returns false </exception> public bool NextSolution() { if (0 == _qid) { Check.Require(!string.IsNullOrEmpty(_name), "PlQuery.NextSolution() _name is required"); IntPtr p = LibPl.PL_predicate(_name, _av.Size, _module); _qid = LibPl.PL_open_query((IntPtr)0, LibPl.PL_Q_CATCH_EXCEPTION, p, _av.A0); } int rval = LibPl.PL_next_solution(_qid); if (0 == rval) { // error uintptr_t ex; // term_t if ((ex = LibPl.PL_exception(_qid)) > 0) { _qid = 0; // to avoid an AccessViolationException on Dispose. E.g. if the query is miss spelled. var etmp = new PlException(new PlTerm(ex)); etmp.Throw(); } } if (rval <= 0) { Free(false); } return(rval > 0); }
public void KomplexPlException() { const int size = 4; const int index = 6; PlTerm term = PlTerm.PlCompound("error", new PlTermV(PlTerm.PlCompound("domain_error", new PlTermV(PlTerm.PlCompound("argv", new PlTermV(size)), new PlTerm(index)) ), PlTerm.PlVar()) ); var ex = new PlException(term); //Assert.AreEqual("Domain error: `argv(_G1, _G2, _G3, _G4)' expected, found `6'", ex.Message); // since swi-prolog version 5.7.6 // Assert.AreEqual("Domain error: `argv(_G60, _G61, _G62, _G63)' expected, found `6'", ex.Message); // since swi-prolog version 5.7.10 // Assert.AreEqual("Domain error: `argv(_G1, _G2, _G3, _G4)' expected, found `6'", ex.Message); // since swi-prolog version 5.9.10 #if _PL_X64 Assert.AreEqual("Domain error: `argv(_G53,_G54,_G55,_G56)' expected, found `6'", ex.Message); #else Assert.AreEqual("Domain error: `argv(_G1,_G2,_G3,_G4)' expected, found `6'", ex.Message); #endif }
private void CheckForException() { uint ex = libpl.PL_exception(_qid); // term_t if (ex > 0) { PlTerm exceptionTerm = new PlTerm(ex); PlException etmp = new PlException(exceptionTerm); _qid = 0; // to avoid an AccessViolationException on Dispose. E.g. if the query is miss spelled. etmp.Throw(); } }