The ISO way to catch a syntax error is to write:
catch(number_codes(Number,"m"),error(syntax_error(_),_), fail).
The first argument is the goal to be protected, the second argument is the pattern to be caught. In this case, you want to catch an error. Errors are all of the form error(E,_)
where the first argument is the concrete error term, in this case syntax_error(_)
. The second argument is implementation defined. So you cannot rely on its precise format.
Never simply catch everything (as @CapelliC) suggested. In this manner you might unintentionally hide some unexpected errors.