O'Reilly logo
  • Joseph Vaughan thinks this is interesting:

function doGet() {
  try{
    var html = HtmlService.createTemplateFromFile('index').evaluate()
        .setTitle('Web App').setSandboxMode(HtmlService.SandboxMode NATIVE);
    var x=t;
  }catch(e){
    html.setContent(e.name + ' on line: ' + e.lineNumber + ' -> ' +
                    e.message);
  }
  return html;
}

From

Cover of Google Apps Script, 2nd Edition

Note

When I run this code, I get an error “cannot call method setContent of undefined”. This is because the var html is only set in the try stanza.

Instead the code in the catch stanza needs to be something like:

> var html = HtmlService.createHtmlOutput(‘Error‘);
> html.append(e.name + ‘ on line: ‘ + e.lineNumber + ‘ -> ‘ +
> e.message);