function TestException() { try { let data = null; data.someProperty = "value"; //This will throw a TypeError } catch(ex) { //Handle the exception: if (ex instanceof TypeError) Logger.log("TypeError occurred: " + ex.message) else if (ex instanceof ReferenceError) Logger.log("ReferenceError occurred: " + ex.message); else Logger.log("An unexpected error occurred: " + ex.message); } } function ValidateRating(aRating) { if (typeof aRating !== "number" || aRating < 1 || aRating > 5) throw "Invalid score: Score must be a number between 1 and 5."; } function TestRating() { ValidateRating(1); ValidateRating(10); } function Recover() { let url = "http://api.apis.guru/v2/list.jsonX";//Invalid end point let options = { 'method' : 'get', 'muteHttpExceptions': true }; RetryCount = 5; while (RetryCount > 0) { try { try { var response = UrlFetchApp.fetch(url); var responseCode = response.getResponseCode(); var responseBody = response.getContentText(); if (responseCode == 200) Logger.log("Successful response: " + responseBody); else { Logger.log("Error response code: " + responseCode); Logger.log("Error response body: " + responseBody); } } finally { RetryCount--; } } catch (e) { Logger.log("Request failed: " + e.message); url = "http://api.apis.guru/v2/list.json";//Valid end point } } }