We start by getting the template file that we want to make a copy of but wrap this within a try/catch. As part of getting the file we include an additional variable (gotTemplateFile) set to either true or false depending upon success, which we can then use to determine if the script should proceed with the next step. We also make use of the logEvent Function to output any errors messages:
try {
// get template file
var templateFile = DriveApp.getFileById(templateFileId);
var gotTemplateFile = true;
}
catch(e) {
logEvent('Problem with template file, error: ' + e);
var gotTemplateFile = false;
}