2 Replies Latest reply on Mar 23, 2012 9:42 AM by jaloren28

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

    jaloren28 Helper

      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(foobar.name+' has an unitialized parameter')}