Skip navigation
Currently Being Moderated

Is there a recommended way to catch undefined parameters in a function?

Mar 22, 2012 1:05 PM

I was working on a script that had a function which recursively called itself. At one point the function had one parameter but eventually I added a second parameter. Unfortunately, i forgot to initialize the second parameter when i recursively called the function within the function. In the extendscript toolkit, this meant that when I hit the part of the function that required the parameter, it would throw an error "object is undefined" without telling me what the object was so I didn't know the issue was the uninitalized parameter. I wish the toolkit was robust enough to instead throw an error like "parameter [name of parameter] is undefined in function [name of function]". That would have immediately told me what was going on.


So is there some way to define a custom function or some test i could add in that would catch the unitialized parameter problem? The one thought i had was to always put an ObjectValid test on the parameters at the beginning of the function like so:


function foobar (parameter1, parameter2)

{ var vFunctionName=foobar;


if (parameter1.ObjectValid()&&parameter2.ObjectValid())

      { // execute code here



       } else {Err(' has an unitialized parameter')}



More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points