5 Calling Prolog from Python
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog Python interface
        • Calling Prolog from Python
          • Janus iterator query
          • Janus iterator apply
          • Janus access to Python locals and globals
          • Janus and Prolog truth
          • Janus class Term
          • Janus class PrologError

5.6 Janus class PrologError

Class janus.PrologError(), derived from the Python class Exception represents a Prolog exception that typically results from calling janus.query_once(), janus.apply_once(), janus.query() or janus.apply(). The class either encapsulates a string on a Prolog exception term using janus.Term. Prolog exceptions are used to represent errors raised by Prolog. Strings are used to represent errors from invalid use of the interface. The default behavior gives the expected message:

>>> x = janus.query_once("X is 3.14/0")['X']
Traceback (most recent call last):
  ...
janus.PrologError: //2: Arithmetic: evaluation error: `zero_divisor'

At this moment we only define a single Python class for representing Prolog exceptions. This suffices for error reporting, but does not make it easy to distinguish different Prolog errors. Future versions may improve on that by either subclassing janus.PrologError or provide a method to classify the error more easily.

PrologError janus.PrologError(TermOrString)
The constructor may be used explicitly, but this should be very uncommon.
String janus.PrologError.__str__()
Return a human readable message for the error using message_to_string/2
String janus.PrologError.__repr__()
Return a formal representation of the error by means of write_canonical/1.