From 32d91449b57d0c266e3c68092288ce3279fadc3f Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sat, 8 Mar 2025 09:12:17 +0100 Subject: [PATCH] ADDED: call_with_error_context/2 See https://github.com/mthom/scryer-prolog/discussions/2839 for more information. --- src/lib/error.pl | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/lib/error.pl b/src/lib/error.pl index fc3b9712..81c676df 100644 --- a/src/lib/error.pl +++ b/src/lib/error.pl @@ -1,5 +1,5 @@ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Written 2018-2023 by Markus Triska (triska@metalevel.at) + Written 2018-2025 by Markus Triska (triska@metalevel.at) I place this code in the public domain. Use it in any way you want. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ @@ -7,7 +7,8 @@ can_be/2, instantiation_error/1, domain_error/3, - type_error/3 + type_error/3, + call_with_error_context/2 ]). @@ -217,3 +218,20 @@ domain_error(Type, Term, Context) :- 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]))). -- 2.54.0