Please don’t take this as anything other than just trying to shine some light on what you seek, which is to cleanup library(rbtrees).
Instead of focusing on the catch/throw part of the question, in looking at it from what is the predicate is_rebtree/1 suppose to do one has to ask, is is_rbtreee/1 a predicate that should return only success or failure?
When I see predicates starting with the word is
I don’t expect side effects, no exceptions, no messages, no binding of values, just success or failure of the predicate.
Digging deeper into how I reason about such is that is_rbtree/1 looks to be a recognizer (think parser that returns either success or failure) and is a wrapper around a parser that suppresses all error messages. In looking at the current code for is_rbtree/1, that is what I am seeing
is_rbtree(X) :-
var(X), !, fail.
is_rbtree(t(Nil,Nil)) :- !.
is_rbtree(t(_,T)) :-
catch(rbtree1(T), msg(_,_), fail).
with rbtree1/1
being the parser that throws.
If a predicate is needed to check if a value is an rb_tree and return the errors then I would expect a parser predicate with 2 arguments, the first augment being the value to be parsed and the second being an option list with an option for what to do with the parsing errors (collect them into a list, print them as found, …). I am not finding an exported predicate for such with SWI-Prolog Red-Black trees. rbtree1/1
would be a good start.
If the data is external data being loaded then I would look to rdf_load/2 for inspiration. However rb_trees tend to be internal so I would look to json_read/2 or similar for inspiration.
When I was searching trusted SWI-Prolog repositories for code that would catch an error and massage specific errors into fail or re-export the error, it was like looking for a needle in a hay stack. Nothing I found exactly matched all three.
HTH
My current list of trusted SWI-Prolog repositories that I search. More are trusted but not in the list as it takes about a minute to search these and I do tens of searches a day.
Click triangle to expand
bench-master
contrib-protobufs-master
docker-swipl-linux-ci-master
packages-bdb-master
packages-chr-master
packages-clib-master
packages-cppproxy-master
packages-http-master
packages-inclpr-master
packages-jpl-master
packages-ltx2htm-master
packages-odbc-master
packages-pcre-master
packages-pengines-master
packages-pldoc-master
packages-RDF-master
packages-real-master
packages-semweb-master
packages-sgml-master
packages-ssl-master
packages-utf8proc-master
packages-xpce-master
packages-yaml-master
packages-zlib-master
pengines-master
plweb-blog-master
plweb-examples-master
plweb-master
plweb-www-master
rclswi-master
swipl-devel-master
swipl-master
swipl-server-js-client-master
swish-master
webstat-master