0

I am using Google Apps Script in a Google Sheet. I added some code recently that was causing an error due to me trying to access locked data. I tried some basic error trapping using Try / Catch and this works fine when I run my code, but in debug mode the program halts execution on the line in question. Am I using Try / Catch wrong, or is there something else I'm missing?

Here's my code:

  for (var i=0;i<userGroups.length;i++) {
    try {
      var temp = userGroups[i].getUsers();
    } catch(error) {
      console.log(error); 
    }
    ...

NOTE: I am NOT using the V8 runtime as it was causing me a lot of issues.

4
  • 1
    Please add a minimal reproducible example including what runtime time are you using (old or Chrome V8). Commented May 25, 2020 at 19:09
  • Did you implement a breakpoint? The debugger is meant to stop at breakpoints. Commented May 26, 2020 at 10:50
  • I've done a number of experiments tonight and the ONLY time I am able to replicate the problem in my post is when I get the error: You do not have permission to view the member list for the group: [email protected] (line 265, file "Code") I can use Try / Catch to trap this error and that works fine when I run my code normally. But when I use debug mode my code breaks on getUsers() (the line in question). Commented May 26, 2020 at 18:55
  • (I tried to edit my post above, but I waited too long.) To be clear, I don't see this issue with any other errors I tried. It only seems to happen with permissions. Commented May 26, 2020 at 19:27

2 Answers 2

2

If you are not using V8, it is an intended behavior that the debugger stops execution at any error - handled or not

  • Indeed, some users even complain about the fact that in V8 this feature has not been maintained.
  • If you on the flipside are happy with the debugger not stopping execution at handled errors - change to V8.
Sign up to request clarification or add additional context in comments.

3 Comments

I was just coming back to post this. An engineer at work wasn't able to reproduce my problem using v8. When he went back to the old version he saw what I was seeing. I'll give v8 another try.
The debugger is pausing on V8 and I would really like to turn it off. :(
It's a stupid feature honestly. It ignores my breakpoint and rather goes on its own journey through a loop. No one can possibly sit through a loop iterating 100's of times and pressing continue each time.
1

To work around the issue of the V8 debugger pausing on an error in a try catch, put the code with the try/catch in a library and call that code from your script by referencing the library. This way the try catch is occurring outside the debugger's control.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.