For any any that PHP might throw an exception, you can enclose it in a try-catch block. Example:
// Collect file list
try {
$optParams = [
'orderBy' => 'modifiedTime',
'pageSize' => $count, # Google default is 100, maximum is 1000
'q' => "mimeType = 'application/vnd.google-apps.spreadsheet' and modifiedTime >= '$modifiedAfter'",
'fields' => 'nextPageToken, files(id,modifiedTime)'
];
$results = $googleService->files->listFiles($optParams);
foreach ($results->getFiles() as $file) {
if ($file->getModifiedTime() <= $modifiedAfter) {
if ($file->getId() <= $idGreaterThan) {
continue;
}
}
$retval[$file->getId()] = $file->getModifiedTime();
}
return $retval;
} catch (\Google_Service_Exception $e) {
echo 'ERROR GOOGLE SERVICE: ';
echo json_encode($e->getErrors());
return null;
}
How should somebody evaluate if catching the error is best practice?