I have a function for which I want to catch the error of requiring too many output arguments and yield a specific message. I attempt to do so with this code excerpt:
lhs = argn(1);
if lhs>3
// More than 3 output parameters
msg = _(“%s: Wrong number of output arguments: %d to %d expected.\n”)
error(msprintf(msg, “spectrogram”, 0, 3))
end
but I got this message:
Wrong number of output arguments.
It seems to be a generic message that takes precedence over the intended one:
spectrogram: Wrong number of output arguments: 0 to 3 expected.
UPDATE: The same happens with input arguments
Thanks,
Federico Miyara
Hello,
If I encapsulate the above code in a function with an explicit number of ouput argument in the prototype
function [a,b,c] =spectrogram()
lhs = argn(1);
if lhs>3
// More than 3 output parameters
msg = _("%s: Wrong number of output arguments: %d to %d expected.\n")
error(msprintf(msg, "spectrogram", 0, 3))
end
end
it’s expected that when you type
[a,b,c,d,e] = spectrogram()
you get
Wrong number of output arguments.
because the check is made by Scilab internals, which compares the actual number of output arguments used v.s. the number of these in the prototype.
If you want to control this yourself you have to use varargout
as output argument (see varargout - Arbitrarily long list of output arguments).
S.
2 Likes