2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
2004-01-23 02:23:51 +00:00
|
|
|
* File: errors.yap *
|
2014-12-24 15:32:29 +00:00
|
|
|
* comments: error messages for YAP *
|
2001-04-09 20:54:03 +01:00
|
|
|
* *
|
2004-06-09 04:32:03 +01:00
|
|
|
* *
|
2004-04-27 17:21:25 +01:00
|
|
|
* *
|
2001-04-09 20:54:03 +01:00
|
|
|
*************************************************************************/
|
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
|
|
|
|
/** @defgroup YAPError Error Handling
|
2016-01-20 22:36:16 +00:00
|
|
|
|
2014-09-11 20:06:57 +01:00
|
|
|
@ingroup YAPControl
|
|
|
|
|
|
|
|
The error handler is called when there is an execution error or a
|
|
|
|
warning needs to be displayed. The handlers include a number of hooks
|
|
|
|
to allow user-control.
|
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
Errors are terms of the form:
|
|
|
|
|
|
|
|
- error( domain_error( Domain, Culprit )`
|
|
|
|
- error( evaluation_error( Expression, Culprit )`
|
|
|
|
- error( existence_error( Object, Culprit )`
|
|
|
|
- error( instantiation_error )`
|
|
|
|
- error( permission_error( Error, Permission, Culprit)`
|
|
|
|
- error( representation_error( Domain, Culprit )`
|
|
|
|
- error( resource_error( Resource, Culprit )`
|
|
|
|
- error( syntax_error( Error )`
|
|
|
|
- error( system_error( Domain, Culprit )`
|
|
|
|
- error( type_error( Type, Culprit )`
|
|
|
|
- error( uninstantiation_error( Culprit )`
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
@{
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2015-07-06 12:04:42 +01:00
|
|
|
*/
|
2014-09-11 20:06:57 +01:00
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
:- system_module( '$_errors', [system_error/2], ['$Error'/1,
|
|
|
|
'$do_error'/2,
|
|
|
|
system_error/3,
|
|
|
|
system_error/2]).
|
2014-04-09 12:39:29 +01:00
|
|
|
|
|
|
|
:- use_system_module( '$messages', [file_location/2,
|
|
|
|
generate_message/3,
|
2016-07-31 16:40:47 +01:00
|
|
|
translate_message/4]).
|
2014-04-09 12:39:29 +01:00
|
|
|
|
|
|
|
|
2016-01-20 22:36:16 +00:00
|
|
|
/**
|
|
|
|
* @pred system_error( +Error, +Cause)
|
|
|
|
*
|
|
|
|
* Generate a system error _Error_, informing the possible cause _Cause_.
|
|
|
|
*
|
|
|
|
*/
|
2016-07-31 16:40:47 +01:00
|
|
|
system_error(Type,Goal) :-
|
2016-01-20 22:36:16 +00:00
|
|
|
'$do_error'(Type,Goal).
|
|
|
|
|
|
|
|
|
|
|
|
'$do_error'(Type,Goal) :-
|
2016-07-31 16:40:47 +01:00
|
|
|
% format('~w~n', [Type]),
|
2016-01-20 22:36:16 +00:00
|
|
|
ancestor_location(Call, Caller),
|
|
|
|
throw(error(Type, [
|
|
|
|
[g|g(Goal)],
|
|
|
|
[p|Call],
|
|
|
|
[e|Caller]])).
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @pred system_error( +Error, +Cause, +Culprit)
|
|
|
|
*
|
|
|
|
* Generate a system error _Error_, informing the source goal _Cause_ and a possible _Culprit_.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* ~~~~~~~~~~
|
|
|
|
* ~~~~~~~~~~
|
|
|
|
*
|
2016-07-31 16:40:47 +01:00
|
|
|
*
|
2016-01-20 22:36:16 +00:00
|
|
|
*/
|
2016-07-31 16:40:47 +01:00
|
|
|
system_error(Type,Goal,Culprit) :-
|
2016-01-20 22:36:16 +00:00
|
|
|
% format('~w~n', [Type]),
|
|
|
|
ancestor_location(Call, Caller),
|
|
|
|
throw(error(Type, [
|
|
|
|
[i|Culprit],
|
|
|
|
[g|g(Goal)],
|
|
|
|
[p|Call],
|
|
|
|
[e|Caller]])).
|
2015-09-21 23:05:36 +01:00
|
|
|
|
2014-10-20 15:40:19 +01:00
|
|
|
'$do_pi_error'(type_error(callable,Name/0),Message) :- !,
|
|
|
|
'$do_error'(type_error(callable,Name),Message).
|
|
|
|
'$do_pi_error'(Error,Message) :- !,
|
|
|
|
'$do_error'(Error,Message).
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
'$Error'(E) :-
|
2003-12-01 17:27:42 +00:00
|
|
|
'$LoopError'(E,top).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-12-01 17:27:42 +00:00
|
|
|
'$LoopError'(_, _) :-
|
2001-04-09 20:54:03 +01:00
|
|
|
flush_output(user_output),
|
|
|
|
flush_output(user_error),
|
|
|
|
fail.
|
2003-12-01 17:27:42 +00:00
|
|
|
'$LoopError'(Error, Level) :- !,
|
|
|
|
'$process_error'(Error, Level),
|
2001-04-09 20:54:03 +01:00
|
|
|
fail.
|
2003-12-01 17:27:42 +00:00
|
|
|
'$LoopError'(_, _) :-
|
2014-08-04 15:45:30 +01:00
|
|
|
flush_output,
|
2001-04-09 20:54:03 +01:00
|
|
|
fail.
|
|
|
|
|
2016-07-31 16:40:47 +01:00
|
|
|
'$process_error'('$forward'(Msg), _) :-
|
|
|
|
!,
|
|
|
|
throw( '$forward'(Msg) ).
|
|
|
|
'$process_error'('$abort', Level) :-
|
|
|
|
!,
|
|
|
|
'$process_error'(abort, Level).
|
|
|
|
'$process_error'(abort, Level) :-
|
|
|
|
!,
|
|
|
|
(
|
|
|
|
Level \== top
|
|
|
|
->
|
|
|
|
throw( abort )
|
|
|
|
;
|
|
|
|
current_prolog_flag(break_level, 0)
|
|
|
|
->
|
|
|
|
print_message(informational,abort(user)),
|
|
|
|
fail
|
|
|
|
;
|
|
|
|
current_prolog_flag(break_level, I0),
|
|
|
|
I is I0-1,
|
|
|
|
current_prolog_flag(break_level, I),
|
|
|
|
throw(abort)
|
|
|
|
).
|
2015-07-06 12:04:42 +01:00
|
|
|
'$process_error'(error(thread_cancel(_Id), _G),top) :- !.
|
2008-04-04 11:02:44 +01:00
|
|
|
'$process_error'(error(thread_cancel(Id), G), _) :- !,
|
|
|
|
throw(error(thread_cancel(Id), G)).
|
2014-05-25 20:52:45 +01:00
|
|
|
'$process_error'(error(permission_error(module,redefined,A),B), Level) :-
|
|
|
|
Level \= top, !,
|
|
|
|
throw(error(permission_error(module,redefined,A),B)).
|
2015-10-18 12:28:02 +01:00
|
|
|
'$process_error'(error(Msg, Where), _) :-
|
2015-11-18 15:06:25 +00:00
|
|
|
print_message(error,error(Msg, Where)), !.
|
2003-12-01 17:27:42 +00:00
|
|
|
'$process_error'(Throw, _) :-
|
2009-03-26 08:54:49 +00:00
|
|
|
print_message(error,error(unhandled_exception,Throw)).
|
2016-01-20 22:36:16 +00:00
|
|
|
|
2016-07-31 16:40:47 +01:00
|
|
|
%% @}
|