/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I place this code in the public domain. Use it in any way you want.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
can_be/2,
instantiation_error/1,
domain_error/3,
- type_error/3
+ type_error/3,
+ call_with_error_context/2
]).
type_error(Type, Term, Context) :-
throw(error(type_error(Type, Term), Context)).
+
+/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ call_with_error_context/2
+
+ See https://github.com/mthom/scryer-prolog/discussions/2839 .
+- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+%% call_with_error_context(+Goal, +Pair)
+%
+% Call _Goal_ with error context _Pair_.
+%
+% Examples of error contexts: `predicate-PI`, `file-Filename` etc.
+
+:- meta_predicate(call_with_error_context(0,+)).
+call_with_error_context(G_0, Pair) :-
+ must_be(pair, Pair),
+ catch(G_0, error(E,Pairs), throw(error(E,[Pair|Pairs]))).