This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/pl/errors.yap

134 lines
3.4 KiB
Plaintext
Raw Normal View History

/*************************************************************************
* *
* YAP Prolog *
* *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
2018-01-22 13:53:17 +00:00
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
2018-01-22 13:53:17 +00:00
* *
* File: errors.yap *
* comments: error messages for YAP *
* *
* *
* *
*************************************************************************/
2018-01-18 14:47:27 +00:00
2018-01-22 13:53:17 +00:00
/** @defgroup YAPErrorHandler Error Handling
2018-01-18 14:47:27 +00:00
2018-01-22 13:53:17 +00:00
@ingroup YAPErrors
2018-06-05 20:51:49 +01:00
@{
2018-01-22 13:53:17 +00:00
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.
2018-01-18 14:47:27 +00:00
2018-01-22 13:53:17 +00:00
Errors are terms of the form:
2018-01-18 14:47:27 +00:00
2018-01-22 13:53:17 +00:00
- 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 )`
2018-01-18 14:47:27 +00:00
*/
2018-01-22 13:53:17 +00:00
:- system_module( '$_errors', [system_error/2], ['$Error'/1,
'$do_error'/2,
system_error/3,
system_error/2]).
2018-01-18 14:47:27 +00:00
2018-01-22 13:53:17 +00:00
:- use_system_module( '$messages', [file_location/2,
generate_message/3,
translate_message/4]).
2018-01-18 14:47:27 +00:00
2018-01-22 13:53:17 +00:00
/**
* @pred system_error( +Error, +Cause)
*
* Generate a system error _Error_, informing the possible cause _Cause_.
*
*/
2018-07-10 23:21:19 +01:00
prolog:system_error(Type,Goal) :-
2018-01-22 13:53:17 +00:00
'$do_error'(Type,Goal).
'$do_error'(Type,Goal) :-
throw(error(Type, print_message(['while calling goal = ~w'-Goal,nl]))).
2018-01-18 14:47:27 +00:00
2018-01-22 13:53:17 +00:00
/**
* @pred system_error( +Error, +Cause, +Culprit)
*
2018-04-09 02:00:51 +01:00
* Generate a system error _Error_, informing the source goal _Cause_
2018-01-22 13:53:17 +00:00
*
*
* ~~~~~~~~~~
* ~~~~~~~~~~
*
*
*/
2018-04-09 02:00:51 +01:00
system_error(Type,Goal) :-
throw(error(Type, print_message(['while calling goal = ~w'-Goal,nl]))) .
2018-01-22 13:53:17 +00: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).
'$Error'(E) :-
'$LoopError'(E, top).
2018-05-24 12:00:10 +01:00
%%
% error_handler(+Error,+ Level)
%
2018-05-27 00:47:03 +01:00
% process an error term.
2018-05-24 12:00:10 +01:00
%
2018-05-27 00:47:03 +01:00
error_handler(Error, Level) :-
2018-05-24 12:00:10 +01:00
'$LoopError'(Error, Level).
2018-01-22 13:53:17 +00:00
'$LoopError'(_, _) :-
2018-10-05 10:27:03 +01:00
flush_output(user_output),
2018-01-22 13:53:17 +00:00
flush_output(user_error),
2018-01-18 14:47:27 +00:00
fail.
2018-01-22 13:53:17 +00:00
'$LoopError'(Error, Level) :- !,
'$process_error'(Error, Level),
2018-01-18 14:47:27 +00:00
fail.
2018-01-22 13:53:17 +00:00
'$LoopError'(_, _) :-
flush_output,
'$close_error',
2018-01-18 14:47:27 +00:00
fail.
'$process_error'('$forward'(Msg), _) :-
2018-01-18 14:47:27 +00:00
!,
2018-01-22 13:53:17 +00:00
throw( '$forward'(Msg) ).
2018-11-25 13:27:48 +00:00
'$process_error'(error(event(abort,I),C), Level) :-
2017-03-23 12:28:46 +00:00
!,
2018-01-18 14:47:27 +00:00
(
2018-11-25 13:27:48 +00:00
current_prolog_flag(break_level, 0),
2018-01-22 13:53:17 +00:00
Level \== top
2018-01-18 14:47:27 +00:00
->
2018-11-25 13:27:48 +00:00
print_message(informational,abort(user)),
fail
;
throw( error(event(abort,I),C) )
2018-01-18 14:47:27 +00:00
).
2018-01-22 13:53:17 +00:00
'$process_error'(error(permission_error(module,redefined,A),B), Level) :-
Level \= top, !,
throw(error(permission_error(module,redefined,A),B)).
'$process_error'(Error, _Level) :-
functor(Error, Severity, _),
2018-05-24 12:00:10 +01:00
print_message(Severity, Error),
!,
'$close_error'.
'$process_error'(error(Type,Info), _, _) :-
print_message(error,error(unhandled_exception(Type),Info)).
2018-01-22 13:53:17 +00:00
%% @}