Native C API - Error Creation
Functions |
p_term * | p_create_instantiation_error (p_context *context) |
| Creates a new instantiation error term within context.
|
p_term * | p_create_type_error (p_context *context, const char *expected_type, p_term *culprit) |
| Creates a new type error term from expected_type and culprit within context.
|
p_term * | p_create_domain_error (p_context *context, const char *expected_domain, p_term *culprit) |
| Creates a new domain error term from expected_domain and culprit within context.
|
p_term * | p_create_existence_error (p_context *context, const char *object_type, p_term *culprit) |
| Creates a new existence error term from object_type and culprit within context.
|
p_term * | p_create_permission_error (p_context *context, const char *operation, const char *permission_type, p_term *culprit) |
| Creates a new permission error term from operation, permission_type, and culprit within context.
|
p_term * | p_create_representation_error (p_context *context, const char *flag) |
| Creates a new representation error term from flag within context.
|
p_term * | p_create_evaluation_error (p_context *context, const char *eval_type) |
| Creates a new evaluation error term from eval_type within context.
|
p_term * | p_create_resource_error (p_context *context, p_term *resource) |
| Creates a new resource error term from resource within context.
|
p_term * | p_create_syntax_error (p_context *context, p_term *term) |
| Creates a new syntax error term from term within context.
|
p_term * | p_create_system_error (p_context *context) |
| Creates a new system error term within context.
|
p_term * | p_create_generic_error (p_context *context, p_term *term) |
| Creates a new generic error term from term within context.
|
Detailed Description
Functions in this module assist with the creation of error terms for builtin predicates. In the predicate documentation, errors are described as follows:
instantiation_error
- Arg is a variable.
type_error(number, Value)
- Value is not a number.
- ...
When the error is generated, the effect is to throw/1 a term of the form error(ErrorTerm, Name / Arity)
where:
- ErrorTerm is a cloned copy of the
instantiation_error
, type_error
, etc term. The term must be cloned so that it will survive backtracking when searching for a catch/3 goal to handle the error.
- Name / Arity is the name of the predicate that generated the error.
Because errors terms can be quite complex, the functions below are provided to assist with the process of creating them from native C code.
Note: Standard Prolog specifies the second argument to error/2 as "implementation-defined". In Plang we have chosen to provide the name of the predicate throwing the error. This may be changed in later versions of Plang; e.g. to include filename and line number information for the call site that generated the error. If that happens, the implementation of these error creation functions will be modified to generate the new form of error term.
Function Documentation
p_term* p_create_domain_error |
( |
p_context * |
context, |
|
|
const char * |
expected_domain, |
|
|
p_term * |
culprit | |
|
) |
| | |
Creates a new domain error term from expected_domain and culprit within context.
The returned term will have the form error(domain_error(expected_domain, culprit), Name / Arity)
. The culprit term will be cloned so that it will survive back-tracking.
Definition at line 141 of file errors.c.
p_term* p_create_evaluation_error |
( |
p_context * |
context, |
|
|
const char * |
eval_type | |
|
) |
| | |
Creates a new evaluation error term from eval_type within context.
The returned term will have the form error(evaluation_error(eval_type), Name / Arity)
.
Definition at line 225 of file errors.c.
p_term* p_create_existence_error |
( |
p_context * |
context, |
|
|
const char * |
object_type, |
|
|
p_term * |
culprit | |
|
) |
| | |
Creates a new existence error term from object_type and culprit within context.
The returned term will have the form error(existence_error(object_type, culprit), Name / Arity)
. The culprit term will be cloned so that it will survive back-tracking.
Definition at line 163 of file errors.c.
p_term* p_create_generic_error |
( |
p_context * |
context, |
|
|
p_term * |
term | |
|
) |
| | |
Creates a new generic error term from term within context.
The returned term will have the form error(term, Name / Arity)
. The term will be cloned so that it will survive back-tracking.
This function is intended for new error types that are not handled by the other functions in this module.
Definition at line 300 of file errors.c.
p_term* p_create_instantiation_error |
( |
p_context * |
context |
) |
|
Creates a new instantiation error term within context.
The returned term will have the form error(instantiation_error, Name / Arity)
.
Definition at line 101 of file errors.c.
p_term* p_create_permission_error |
( |
p_context * |
context, |
|
|
const char * |
operation, |
|
|
const char * |
permission_type, |
|
|
p_term * |
culprit | |
|
) |
| | |
Creates a new permission error term from operation, permission_type, and culprit within context.
The returned term will have the form error(permission_error(operation, permission_type, culprit), Name / Arity)
. The culprit term will be cloned so that it will survive back-tracking.
Definition at line 185 of file errors.c.
p_term* p_create_representation_error |
( |
p_context * |
context, |
|
|
const char * |
flag | |
|
) |
| | |
Creates a new representation error term from flag within context.
The returned term will have the form error(representation_error(flag), Name / Arity)
.
Definition at line 207 of file errors.c.
p_term* p_create_resource_error |
( |
p_context * |
context, |
|
|
p_term * |
resource | |
|
) |
| | |
Creates a new resource error term from resource within context.
The returned term will have the form error(resource_error(resource), Name / Arity)
. The resource term will be cloned so that it will survive back-tracking.
Definition at line 245 of file errors.c.
p_term* p_create_syntax_error |
( |
p_context * |
context, |
|
|
p_term * |
term | |
|
) |
| | |
Creates a new syntax error term from term within context.
The returned term will have the form error(syntax_error(term), Name / Arity)
. The term will be cloned so that it will survive back-tracking.
Definition at line 264 of file errors.c.
p_term* p_create_system_error |
( |
p_context * |
context |
) |
|
Creates a new system error term within context.
The returned term will have the form error(system_error, Name / Arity)
.
Definition at line 281 of file errors.c.
p_term* p_create_type_error |
( |
p_context * |
context, |
|
|
const char * |
expected_type, |
|
|
p_term * |
culprit | |
|
) |
| | |
Creates a new type error term from expected_type and culprit within context.
The returned term will have the form error(type_error(expected_type, culprit), Name / Arity)
. The culprit term will be cloned so that it will survive back-tracking.
Definition at line 119 of file errors.c.