代码之家  ›  专栏  ›  技术社区  ›  bugmagnet

在GoogleApps脚本中,超时可以通过try/catch捕获,还是在更高级别上发生?

  •  0
  • bugmagnet  · 技术社区  · 5 年前

    超时是否可捕获?我是否可以将最有可能的违规者包装在一个try/catch中,并在适当的时候对catch块进行评估?还是我一直在努力让事情变得如此难以置信,以至于我从来没有撞到墙?

    0 回复  |  直到 5 年前
        1
  •  1
  •   Sourabh Choraria    5 年前

    鉴于您正在调用多个函数,我建议您创建一个触发器,而不是使用 ScriptApp.newTrigger ,这可以通过引入另一个函数来触发,该函数检查脚本是否已超过预定的执行时间(如果最大值为6,则可以将其设置为5以确保安全)。

    指的是这样的事情-

    // var today = new Date();
    // 'today' is declard in the original script
    
    function isTimeUp(today) {
      var now = new Date();
      return now.getTime() - today.getTime() > 30000;
      // 30000 = 30 seconds; this is the threshold limit
      // you are free to setup your own threshold limit
    }
    
    

    here .timeBased() 触发但是,您可以使用不同类型的触发器。