Why create an error if you already have the necessary arguments to proceed?
It seems everywhere I look coders especially new ones are eager to throw errors even when there are still easy workarounds. The end-user may not even be a programmer. Think of them as your customers. They may not think too kindly with using applications that are too sensitive to errors instead of self-correcting when possible.
My preferred approach is to always avoid error when possible. Here we can drop (not ignore) trailing arguments from evaluation but the end-user must always be alerted (warned) so he can decide if the output is still useful. A nice user-friendly way is to alert with an Echo[warning message]
which looks very similar to error messages. These are hard to ignore but we can still proceed with evaluation.
Notice how much cleaner the code is now and as a bonus it is self-correcting. That is a win-win for everyone. You put out a better product and code is easier to manage.
1. A Good Approach: 1 Definition
Remove[f];
f[x_, y_, z___] := Block[
{
msg="2 args expected pos 3 not included in evaluation."
},
If[Length@{z} > 0, Echo@msg];
{x, y}
];
f[1, 2, 3]
{1, 2}
>> 2 args expected pos 3 not included in evaluation .
2. Even Better: Recursive Calls
(* definitions *)
Remove@f;
f[x_, y_,
z__] := (Echo[{z}, "2 args expected, pos 3 dropped \[Rule]"];
f[x, y]);
f[x_, y_] := {x, y};
(* input *)
seq = Range[1, 5] /. List -> Sequence;
f[seq](* this is just f[1,2,3,4,5] *)
f[a, b]
f[0, 0]
(* output *)
>>2 args expected, pos 3 dropped -> {3,4,5}
{1,2}
{a,b}
{0,0}