Skip to content

Instantly share code, notes, and snippets.

@phillypb
Last active October 17, 2022 12:02
Show Gist options
  • Save phillypb/ec7a1029afdda37d3a8560a9602fc264 to your computer and use it in GitHub Desktop.
Save phillypb/ec7a1029afdda37d3a8560a9602fc264 to your computer and use it in GitHub Desktop.
/*
Testing the ability to search a 'Catch' error message and display a specific
one based upon it.
*/
function breakMe() {
try {
// get this Google Drive File
var file = DriveApp.getFilById('ENTER FILE ID HERE');
// log message
Logger.log('Function worked');
}
catch (error) {
// log message
Logger.log('Function failed');
// log message
Logger.log("Catch error is: " + error);
// convert 'catch' message to string and perform JavaScript 'match' for keywords
var errorString = error.toString();
var matching = errorString.match(/is not a function/gi);
Logger.log(matching);
// test if 'match' is true to display specific log message
if (matching) {
// log message
Logger.log('True');
}
else {
// log message
Logger.log('False');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment