I am fairly new to google apps script and I came across this issue while trying out tutorial on “Your First Custom Function”.
=in2mm(1) -> 25.4
=in2mm(2) -> 50.8
=in2mm() -> #ERROR (error: input must be a number (line 6))
=in2mm(pi()) -> 79.7964534011807
=in2mm(a) -> #NAME? (error: Unknown range name a)
=in2mm(*) -> #ERROR (error: Parse error)
I am trying to understand the usage of “throw” function in google apps script. How is it able to produce the “input must be a number” in my line 3 whereas line 5 and 6 produces some other results?
You could make the error message more explicit by adding some case handling like this :
But the argument has to be ‘valid’ to be handled by the function… in you example
=in2mm(a)a is interpreted as a named region and since you don’t have a region called ‘a’ it thows an error before trying to execute the function. That’s why the error message doesn’t come from the function itself but from the ‘engine’ under the spreadsheet.The other example
=in2mm(*)return a Parse error for the same reason, the argument is not valid and in this case it cannot be a range either… you could also try + or – , it will try to calculate something but it can’t and again the error message comes from the spreadsheet, not from your function.Try to use a valid range and change the values in the target cell, you’ll see completely different results. For example in
A2write=in2mm(A1)and play withA1Hoping I made things a (little) bit clearer 😉