Try Catch in Google Script Library stopping debugger in calling script

20 views
Skip to first unread message

Paul Prachyl

unread,
Sep 6, 2022, 3:20:36 PM9/6/22
to Google Apps Script Community
I have this code in a google script library :
function getValue(obj, path) {
  if (!path) { return obj; }
  var properties = path.split('.');
  try {
     return getValue(obj[properties.shift()], properties.join('.'));
  }
  catch (err) {
    Logger.log("no value for %s, error = %s",properties,err);
    if (err == "TypeError") {
       return null;
     }
  }
}

I'm calling it by referencing the library and the function like this:
function getValuecall(obj, path) {
  let r = BurnupGetValue.getValue(obj, path); 
  return r;
 }

if the catch in getValue(obj, path) - in the library BurnupGetValue - executes and returns null, then the new IDE debugger stops at the "return r" line of the calling function getValuecall.

I don't understand why. The catch error is happening in a library NOT in the code in the IDE. I put it in a library so that this wouldn't stop the IDE. 

The other interesting thing is, the IDE only stops on "return r" line, if I have a breakpoint in the IDE that I have stopped at BEFORE executing this code. In other works, I'm in the IDE, I stop at a breakpoint, then I continue execution and the condition described above is triggered....


Thanks



Reply all
Reply to author
Forward
0 new messages