]> Repositorios git - scryer-prolog.git/commitdiff
ADDED: variants of errors promoting call_with_error_context/2
authorMarkus Triska <[email protected]>
Sat, 2 Aug 2025 07:55:47 +0000 (09:55 +0200)
committerMarkus Triska <[email protected]>
Sat, 9 Aug 2025 08:11:25 +0000 (10:11 +0200)
A good example of call_with_error_context/2 was recently provided by
@Skgland in d907f86c8d3bf5b5429c9f53187b65473fcbfce0. Many thanks!

src/lib/error.pl

index aebc91edec6b0c9f08285510bc63532ac8d99adb..e7f0f87c54d6758ca2f1d0aca50e8cd242ada3b9 100644 (file)
@@ -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)).