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
var(X), !, fail.
is_rbtree(t(Nil,Nil)) :- !.
catch(rbtree1(T), msg(_,_), fail).
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.
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