6.100 How to check call againt wrong number of arguments of wrong type?

In Mathematica, when calling function  foo[x]  and the function is defined to take two arguments (say), then Mathematica will not issue an error and will use  f[x] unevaluated. This can cause hard to detect errors as the call is meant to be f[x,y].

To check for this, add an error message, like this

foo[x_Integer,y_Integer]:=x*y; 
foo::argerr="Wrong call in ``. Arguments are either wrong type or wrong number of arguments used."; 
err:foo[___]:=(Message[foo::argerr,HoldForm@err]; $Failed);
 

Now if we do

foo[1,2]
 

Then it works and returns 2. But if we make mistake and type

foo[1] 
 
    foo::argerr: Wrong call in foo[1]. Arguments are either wrong type or wrong number of arguments used.
 

This makes the code more robust for wrong call made. This has to be done for each function defined if we want to detect such bad calls.