Last active
October 17, 2022 12:02
-
-
Save phillypb/ec7a1029afdda37d3a8560a9602fc264 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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