# Unnecessary error messages

f::args="1 is not a prorper table.";

SetAttributes[f,HoldAll]

f[tab_/;ListQ[ReleaseHold@tab]===False]:=Message[f::args,HoldForm@tab]

f[tab_]:=ListPlot[ReleaseHold@tab]

g=Table[{i,i^2},{i,10}];


In this code I want to ListPlot only proprly defined tables. If I run f[g[[2;;,{1,2}]]] this gives expected plot. But if I by mistake type f[g[[2;;{1,2}]]] this gives error message from Part and also my message from f, but I want in this error case to see only message from f and no messages from Mathematica functions. How to make f to behave this way?

Thanks.

Let's assume you have a good reason to for HoldAll attribute even though your example does not need it.

• you don't need to use ReleaseHold because there is no explicit Hold there, the argument is held and using Condition or PatternTest will result it being evaluated anyway.

• ListQ should return True or False so ! ListQ[...] is more idiomatic than ListQ[..]===False]

So your original example can be rewritten as:

f[tab_ /; !ListQ[tab] ]:=Message[f::args, HoldForm@tab]


Now, if you want to suppress other messages you can use Quiet. Those messages are issued when you are checking the condition so you can do:

 f[tab_ /; Quiet[!ListQ[tab]] ]:=Message[f::args, HoldForm@tab]

• Thanks for the answer! Actually I have a function of two arguments (two tables, or lists) that I want to ListPlot. The function's body is Manipulate with InputFields for the input arguments, and other controls (ranges, labels, grids etc.). One possibility is using InputField[..., String] and then ToExpression@ in ListPlot. I decided to try another idea of using HoldAll to suppress evaluation arguments in corresponding InputFields. So then I need ReleaseHold inside Manipulate, and I used this in my simple exmaple. Your suggestion works well, thank you!
– Alx
Jul 16 '19 at 13:37
• But now I don't get how to make smth like this for checking arguments of InputField. If one dcides to edit initial tables from function input (in InputField) and makes this kind of typo--- one gets myriad error messages from Mathematica ...
– Alx
Jul 16 '19 at 13:41
• Well, I can add Enabled->False to InputField to prevent erroneous editing.
– Alx
Jul 16 '19 at 14:23
• @Sam_1q I find it hard to grasp your problem only from this description but I've seen your next question so let me take a look.
– Kuba
Jul 17 '19 at 6:26