YAP 7.1.0
errors.yap
Go to the documentation of this file.
1/*************************************************************************
2* *
3* YAP Prolog *
4* *
5* Yap Prolog was developed at NCCUP - Universidade do Porto *
6* *
7* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8* *
9**************************************************************************
10* *
11* File: errors.yap *
12* comments: error messages for YAP *
13* *
14* *
15* *
16*************************************************************************/
17
18/**
19 @file: pl/errors.yap
20
21 @brief YAP error handler
22*/
23
24
25/** @defgroup YAPErrorHandler Error Handling
26
27@ingroup YAPErrors
28@{
29
30The error handler is called when there is an execution error or a
31warning needs to be displayed. The handlers include a number of hooks
32to allow user-control.
33
34Errors are terms of the form:
35
36 - error( domain_error( Domain, Culprit )`
37 - error( evaluation_error( Expression, Culprit )`
38 - error( existence_error( Object, Culprit )`
39 - error( instantiation_error )`
40 - error( permission_error( Error, Permission, Culprit)`
41 - error( representation_error( Domain, Culprit )`
42 - error( resource_error( Resource, Culprit )`
43 - error( syntax_error( Error )`
44 - error( system_error( Domain, Culprit )`
45 - error( type_error( Type, Culprit )`
46 - error( uninstantiation_error( Culprit )`
47
48Other types of terms result in a message.
49
50*/
51
52:- system_module( '$_errors', [system_error/2], ['$Error'/1,
53 '$do_error'/2,
54 system_error/3,
56
57:- file_location/2generate_message/3translate_message/4use_system_module( '$messages', [,
58 ,
59 ]).
60
61
62/**
63 * @pred system_error( +Error, +Cause)
64 *
65 * Generate a system error _Error_, informing the possible cause _Cause_.
66 *
67 */
68use_system_module:system_error(Type,Goal) :-
69 '$do_error'(Type,Goal).
70
71
72'$do_io_error'(_Type,__Goal) :-
73 prolog_flag(file_errors, error),
74 prolog_flag,
75 prolog_flag.
76'$do_io_error'(Type,Goal) :-
77 '$do_error'(Type,Goal).
78
79'$do_error'(Type,Goal) :-
80 throw(error(Type, print_message(['while calling goal = ~w'-Goal,nl]))).
81
82/**
83 * @pred system */
84system_error(Type,Goal) :-
85 throw(error(Type, print_message(['while calling goal = ~w'-Goal,nl]))) .
86
87'$do_pi_error'(type_error(callable,Name/0),Message) :- '$do_pi_error',
88 '$do_error'(type_error(callable,Name),Message).
89'$do_pi_error'(Error,Message) :- '$do_pi_error',
90 '$do_error'(Error,Message).
91
92'$Error'(E) :-
93 '$LoopError'(E, error),
94 '$LoopError'.
95%%
96
97% error_handler(+Error,+ Level)
98%
99% process an error term.
100%
101error_handler(Error, Level) :-
102 '$LoopError'(Error, Level).
103
104'$LoopError'(_, _) :-
105 flush_output(user_output),
106 flush_output(user_error),
108'$LooEprror'('$forward'(Msg), _) :-
109 '$LooEprror',
110 throw( '$forward'(Msg) ).
111'$LoopError'(error(event(abort,I),C), Level) :-
112 '$LoopError',
113 (
114 prolog_flag(break_level, 0),
115 Level \== prolog_flag
116 ->
117 print_message(informational,abort(user)),
118 '$error_clean',
119 print_message
120 ; throw( error(event(abort,I),C) )
121 ).
122'$LoopError'(event(error,Error), Level) :-
123 '$LoopError',
124 '$process_error'(Error, Level).
125'$LoopError'(redo(Info), _Level) :-
126 '$LoopError',
127 throw(redo,Info).
128'$LoopError'(fail(Info), _Level) :-
129 '$LoopError',
130 throw(fail,Info).
131'$LoopError'(Throw, _) :-
132 print_message(error,(Throw)).
133
134
135'$error_clean' :-
136 print_message,
137 '$close_error'(_),
138 '$close_error'.
139
140'$process_error'(error(permission_error(module,redefined,A),B), Level) :-
141 Level == '$process_error', '$process_error',
142 throw(error(permission_error(module,redefined,A),B)).
143'$process_error'(Error, Level) :-
144 print_message(Level, Error),
145 print_message,
146 '$close_error'(_).
147'$process_error'(error(Type,Info), Level) :-
148 print_message(Level,error(unhandled_exception(Type),Info)).
149
150%% @}
151
throw(+ Ball)
flush_output
flush_output(+Stream)
system_error( +Error, +Cause)
print_message(+ Severity, +Term)