existence
tuprolog.solve.exception.error.existence
¶
Existence errors: an operation refers to something that does not exist, e.g. a predicate.
ISO Prolog's existence_error(Kind, Culprit) error, thrown as
error(existence_error(Kind, Culprit), Extra), means that the object Culprit, of the kind
Kind, does not exist: e.g. calling an undefined predicate foo/1 throws
existence_error(procedure, foo/1) (when the unknown flag is error; by default it only
warns, see tuprolog.solve.exception.warning), and reading from a stream alias never opened
throws existence_error(stream, Alias).
The error is an ExistenceError, and the kinds of objects are the values of the ObjectType
enumeration (also available as the OBJECT_* constants), including OOPLib's aliases, methods,
constructors, and properties (see tuprolog.solve.libs). Build errors with
existence_error_for_procedure, existence_error_for_stream, existence_error_for_source_sink,
existence_error_for_resource, or existence_error.
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> existence_error_for_procedure(context, signature("foo", 1)).error_struct
error(existence_error(procedure, foo/1), 'Procedure `foo/1` does not exist')
See Also
2P-Kt's documentation on errors and exceptions.
ExistenceError
module-attribute
¶
ExistenceError = errors.ExistenceError
The existence error, thrown as error(existence_error(Kind, Culprit), _).
It means that there is no object Culprit of kind Kind.
The JVM class (also a Python LookupError and a tuprolog.errors.PrologExistenceError).
Members (snake_case aliases as well): expected_object, the ObjectType; culprit, the term
naming the missing object; besides those of tuprolog.solve.exception.LogicError (e.g. type,
error_struct, message).
ObjectType
module-attribute
¶
ObjectType = ExistenceError.ObjectType
The enumeration of the kinds of objects of existence errors (2P-Kt's ObjectType).
Each value (also available as an OBJECT_* constant) is the Kind of an
existence_error(Kind, Culprit) term: to_term() gives it as an atom (e.g. procedure).
ObjectType.of(NAME) (upper-case names only) and ObjectType.fromTerm(term) look a value up
(see object_type, accepting any case).
OBJECT_PROCEDURE
module-attribute
¶
OBJECT_PROCEDURE = ObjectType.PROCEDURE
procedure: a predicate (the culprit is its indicator, e.g. foo/1).
OBJECT_SOURCE_SINK
module-attribute
¶
OBJECT_SOURCE_SINK = ObjectType.SOURCE_SINK
source_sink: a source or sink of streams, e.g. a file, or a stream alias.
OBJECT_RESOURCE
module-attribute
¶
OBJECT_RESOURCE = ObjectType.RESOURCE
resource: a resource, e.g. one to load.
OBJECT_OOP_ALIAS
module-attribute
¶
OBJECT_OOP_ALIAS = ObjectType.OOP_ALIAS
oop_alias: an OOPLib alias ($Alias) or type name (see tuprolog.solve.libs).
OBJECT_OOP_METHOD
module-attribute
¶
OBJECT_OOP_METHOD = ObjectType.OOP_METHOD
oop_method: a method or attribute of an object, called through OOPLib.
OBJECT_OOP_CONSTRUCTOR
module-attribute
¶
OBJECT_OOP_CONSTRUCTOR = ObjectType.OOP_CONSTRUCTOR
oop_constructor: a constructor of a type, called through OOPLib.
OBJECT_OOP_PROPERTY
module-attribute
¶
OBJECT_OOP_PROPERTY = ObjectType.OOP_PROPERTY
oop_property: a property of an object, accessed through OOPLib.
existence_error
¶
existence_error(
context: ExecutionContext,
type: ObjectType,
culprit: Term,
message: str,
) -> ExistenceError
Creates an existence error for any kind of object, with a custom message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
type
|
ObjectType
|
the kind of the missing object (e.g. |
required |
culprit
|
Term
|
the term naming the missing object. |
required |
message
|
str
|
the error message. |
required |
Returns:
| Type | Description |
|---|---|
ExistenceError
|
The error, thrown as |
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
>>> existence_error(context, OBJECT_OOP_METHOD, atom("foo"), "no method foo").type
existence_error(oop_method, foo)
existence_error_for_source_sink
¶
existence_error_for_source_sink(
context: ExecutionContext, alias: Atom | str
) -> ExistenceError
Creates the existence error for a stream alias no stream has.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
alias
|
Atom | str
|
the alias, as an atom or a string. |
required |
Returns:
| Type | Description |
|---|---|
ExistenceError
|
The error, thrown as |
existence_error_for_procedure
¶
existence_error_for_procedure(
context: ExecutionContext, procedure: Signature
) -> ExistenceError
Creates the existence error for an undefined predicate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the undefined predicate. |
required |
Returns:
| Type | Description |
|---|---|
ExistenceError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> existence_error_for_procedure(context, signature("foo", 1)).type
existence_error(procedure, foo/1)
existence_error_for_stream
¶
existence_error_for_stream(
context: ExecutionContext, stream: Term
) -> ExistenceError
Creates the existence error for a stream that does not exist (e.g. a closed one).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
stream
|
Term
|
the term denoting the stream. |
required |
Returns:
| Type | Description |
|---|---|
ExistenceError
|
The error, thrown as |
existence_error_for_resource
¶
existence_error_for_resource(
context: ExecutionContext, name: str
) -> ExistenceError
Creates the existence error for a missing resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
name
|
str
|
the name of the resource. |
required |
Returns:
| Type | Description |
|---|---|
ExistenceError
|
The error, thrown as |
object_type
¶
object_type(name: str | Term) -> ObjectType
The ObjectType named by a string or an atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | Term
|
the name, as a string or an atom (case-insensitive, e.g. |
required |
Returns:
| Type | Description |
|---|---|
ObjectType
|
The matching |
Raises:
| Type | Description |
|---|---|
IllegalArgumentException
|
if no |
Note
Unlike the other error enumerations, 2P-Kt's ObjectType.of and fromTerm only accept
upper-case names: this function upper-cases strings and atoms first.
Examples:
>>> from tuprolog.core import atom
>>> from tuprolog.solve.exception.error.existence import *
>>> object_type("procedure") == object_type(atom("procedure")) == OBJECT_PROCEDURE
True