1

why does in the example 1 the console log is executed while in example 2 it's not executed ?

//Example 1
try {
    console.log("Trying to connect");
    google.script.run
        .withSuccessHandler( function(response) {
            console.log(response);
        })
    .sendText(data);
} catch {
    console.log("No connection");
}

//Example 2
try {
    google.script.run
        .withSuccessHandler( function(response) {
            console.log(response);
        })
    .sendText(data);
    console.log("Trying to connect");
} catch {
    console.log("No connection");
}

Thanks in advance

2
  • 1
    Which console.log? unclear. Commented Oct 3, 2018 at 22:13
  • ups sorry mate did not saw that someone wrote something here. From the outside oh the thread/topic it's not possible to see that kind of reply it seems. Commented Oct 3, 2018 at 22:26

1 Answer 1

2

I assume your question is about the Trying to connect message.

When an error happens in a try block, the rest of the code in the block is skipped, and it goes to the catch block instead.

In both examples, you're getting an error in google.script.run(). In example 1, you log the message before the error, so the log message is shown, then it goes to the catch block. In example 2, you get the error before you log the message, so it goes directly to the catch block and skips the console.log("Trying to connect"); line.

Sign up to request clarification or add additional context in comments.

4 Comments

Yehh it was that indeed my question. Tought the message would be not block even if it comes after the error. Thanks for the answer and a fast one.
google.script.run is async client-server communication. Any error in the server function is ignored by the example code here. Why do you think it is throwing an error?
@tehhowch If it's not throwing an error, the console.log() would be executed. If it's not connected, that may throw an error synchronously.
Well in this particular case it's trowing because i am running the web page outside of the google api at my home to test the page it self not the javascript and i noted the message was not being printed . Them i try to place the message before the google command and it printed .

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.