View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2019, VU University Amsterdam
    7    All rights reserved.
    8
    9    Redistribution and use in source and binary forms, with or without
   10    modification, are permitted provided that the following conditions
   11    are met:
   12
   13    1. Redistributions of source code must retain the above copyright
   14       notice, this list of conditions and the following disclaimer.
   15
   16    2. Redistributions in binary form must reproduce the above copyright
   17       notice, this list of conditions and the following disclaimer in
   18       the documentation and/or other materials provided with the
   19       distribution.
   20
   21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   32    POSSIBILITY OF SUCH DAMAGE.
   33*/
   34
   35:- module(error_handler,
   36          [ check_acyclic/3,		% ?Term,+Predicate,+Arg
   37            check_atom/3,		% ?Term,+Predicate,+Arg
   38            check_callable/3,		% ?Term,+Predicate,+Arg
   39            check_integer/3,		% ?Term,+Predicate,+Arg
   40            check_nonvar/3,		% ?Term,+Predicate,+Arg
   41            check_nonvar_list/3,	% ?Term,+Predicate,+Arg
   42%           check_one_thread/3,         % +Operation,+Object_Type,+Predicate
   43            check_stream/3,		% ?Term,+Predicate,+Arg
   44            check_var/3,		% ?Term,+Predicate,+Arg
   45            check_ground/3,		% ?Term,+Predicate,+Arg
   46
   47            domain_error/4,             % +Valid_type,-Culprit,+Predicate,+Arg
   48
   49            print_backtrace/1,		% +Backtrace
   50
   51            xsb_error_get_tag/2,        % +ErrorTerm, -Formal
   52            xsb_error_get_message/2     % +ErrorTerm, -Message
   53          ]).   54:- use_module(library(error)).   55:- use_module(library(prolog_stack)).

XSB compatible error handling

*/

   60check_acyclic(Term, _Pred, _Arg)     :- must_be(acyclic, Term).
   61check_atom(Term, _Pred, _Arg)        :- must_be(atom, Term).
   62check_callable(Term, _Pred, _Arg)    :- must_be(callable, Term).
   63check_integer(Term, _Pred, _Arg)     :- must_be(integer, Term).
   64check_nonvar(Term, _Pred, _Arg)      :- must_be(nonvar, Term).
   65check_nonvar_list(Term, _Pred, _Arg) :- must_be(list(nonvar), Term).
   66check_stream(Term, _Pred, _Arg)      :- must_be(stream, Term).
   67check_var(Term, _Pred, _Arg)         :- must_be(var, Term).
   68check_ground(Term, _Pred, _Arg)      :- must_be(ground, Term).
 xsb_error_get_tag(+Term, -Tag) is semidet
Tag is the formal part of an error(Formal,Context) term.
   74xsb_error_get_tag(error(Tag, _), Tag).
 xsb_error_get_message(+Term, -Message) is semidet
Message is the additional explanation context for an error term,
   80xsb_error_get_message(error(_, Context), Message) :-
   81    error_context_message(Context, Message).
   82
   83error_context_message(Var, Var) :-
   84    var(Var),
   85    !.
   86error_context_message(context(Message, _Stack), Message).
 domain_error(+Valid_type, -Culprit, +Predicate, +Arg)
Throws a domain error.
   92domain_error(Type, Culprit, _Pred, _Arg) :-
   93    domain_error(Type, Culprit).
 print_backtrace(+Backtrace)
This predicate, which is used by XSB’s default error handler, prints a backtrace structure to XSB’s standard error stream.
  100print_backtrace(Backtrace) :-
  101    print_prolog_backtrace(user_error, Backtrace).
  102
  103
  104		 /*******************************
  105		 *            MESSAGES		*
  106		 *******************************/
  107
  108:- multifile prolog:message//1.  109
  110prolog:message(aborted(Text)) -->
  111    [ '(abort) ~w'-[Text] ]