Skip to content

system

tuprolog.solve.exception.error.system

System errors: internal problems, e.g. exceptions raised by the code implementing predicates.

ISO Prolog's system_error error, thrown as error(system_error, Extra), reports problems of the implementation rather than of the program: in this library, notably, exceptions raised by Python primitives that are not logic errors (see tuprolog.solve.primitive.python_error), and terms thrown by throw/1 that no catch/3 caught. Prolog code can still catch them.

The error is a SystemError (the JVM class: import it explicitly, as it shadows Python's built-in name). Build errors with system_error.

Examples:

>>> from tuprolog.solve.prolog import prolog_solver
>>> error = prolog_solver().solve_once("throw(oops)").get_exception()
>>> error.type, error.message
(system_error, 'Uncaught exception `oops`')
See Also

2P-Kt's documentation on errors and exceptions.

system_error

system_error(
    context: ExecutionContext, exception: Any
) -> SystemError

Creates the system error wrapping an uncaught error, exception, or thrown term.

Parameters:

Name Type Description Default
context ExecutionContext

the execution context in which the error occurs (e.g. a request's context).

required
exception Any

a tuprolog.solve.exception.LogicError left uncaught (its contexts are kept), a JVM exception (becoming the cause), or a thrown tuprolog.core.Term.

required

Returns:

Type Description
SystemError

The error, thrown as error(system_error, Message).

Examples:

>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import atom
>>> system_error(context, atom("oops")).message
'Uncaught exception `oops`'