From 86dc22a850730fafdd876926522ddf5c1c126f36 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sat, 2 Aug 2025 09:55:47 +0200 Subject: [PATCH 1/3] ADDED: variants of errors promoting call_with_error_context/2 A good example of call_with_error_context/2 was recently provided by @Skgland in d907f86c8d3bf5b5429c9f53187b65473fcbfce0. Many thanks! --- src/lib/error.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/lib/error.pl b/src/lib/error.pl index aebc91ed..e7f0f87c 100644 --- a/src/lib/error.pl +++ b/src/lib/error.pl @@ -5,8 +5,11 @@ :- module(error, [must_be/2, can_be/2, + instantiation_error/0, instantiation_error/1, + domain_error/2, domain_error/3, + type_error/2, type_error/3, call_with_error_context/2 ]). @@ -215,8 +218,25 @@ list_or_partial_list(Ls) :- /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Shorthands for throwing ISO errors. + + The variants without context promote the use of + call_with_error_context/2. + + The variants *with* context would not have been needed if + call_with_error_context/2 had been found earlier. In the future, + we may be able to remove them. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ +instantiation_error :- + throw(error(instantiation_error, [])). + +domain_error(Type, Term) :- + throw(error(domain_error(Type, Term), [])). + +type_error(Type, Term) :- + throw(error(type_error(Type, Term), [])). + + instantiation_error(Context) :- throw(error(instantiation_error, Context)). From bc4689ca4a0de960a916cf363f84031bd502256b Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sat, 9 Aug 2025 10:19:49 +0200 Subject: [PATCH 2/3] ADDED: representation_error/1 --- src/lib/error.pl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/error.pl b/src/lib/error.pl index e7f0f87c..e7568c75 100644 --- a/src/lib/error.pl +++ b/src/lib/error.pl @@ -6,10 +6,11 @@ :- module(error, [must_be/2, can_be/2, instantiation_error/0, - instantiation_error/1, domain_error/2, - domain_error/3, type_error/2, + representation_error/1, + instantiation_error/1, + domain_error/3, type_error/3, call_with_error_context/2 ]). @@ -221,10 +222,6 @@ list_or_partial_list(Ls) :- The variants without context promote the use of call_with_error_context/2. - - The variants *with* context would not have been needed if - call_with_error_context/2 had been found earlier. In the future, - we may be able to remove them. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ instantiation_error :- @@ -236,6 +233,14 @@ domain_error(Type, Term) :- type_error(Type, Term) :- throw(error(type_error(Type, Term), [])). +representation_error(Flag) :- + throw(error(representation_error(Flag), [])). + +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + The variants *with* context would not have been needed if + call_with_error_context/2 had been found earlier. In the future, + we may be able to remove them. +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ instantiation_error(Context) :- throw(error(instantiation_error, Context)). From ee39be4361b8443fb94bb47ec0f25c0011d1c33f Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sat, 9 Aug 2025 10:22:28 +0200 Subject: [PATCH 3/3] ADDED: resource_error/1 --- src/lib/error.pl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/error.pl b/src/lib/error.pl index e7568c75..93426a09 100644 --- a/src/lib/error.pl +++ b/src/lib/error.pl @@ -9,6 +9,7 @@ domain_error/2, type_error/2, representation_error/1, + resource_error/1, instantiation_error/1, domain_error/3, type_error/3, @@ -236,6 +237,9 @@ type_error(Type, Term) :- representation_error(Flag) :- throw(error(representation_error(Flag), [])). +resource_error(Resource) :- + throw(error(resource_error(Resource), [])). + /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The variants *with* context would not have been needed if call_with_error_context/2 had been found earlier. In the future,