There is nothing wrong on using DriveApp.getFileById(id)
to check if a file "exists" based on it's id, other than the file might actually exists but the Google Apps Script effective user hasn't access to that file.
The above because the reference documentation specify that this method will throw an exception, so it's perfectly fine to use try...catch
to catch that exception.
If you might want to do something more sofisthicated like having a default handler for the expected exception and another for unexpected exceptions. If your scripts users is a small group that all have set their Google account language to English it is something easy, but if you are planning to write and addon, this could be hard as Google Apps Script exceptions only return a string message and it depends on the effective account language. Fortunately someone already did a lot of work to handel this, created a library and shared in GitHub --> https://github.com/RomainVialard/ErrorHandler
From https://github.com/RomainVialard/ErrorHandler/blob/master/src/ErrorHandler.gs.js
// "No item with the given ID could be found, or you do not have permission to access it." - eg:Drive App.getFileById
"No item with the given ID could be found, or you do not have permission to access it.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'en' },
"Không tìm thấy mục nào có ID đã cung cấp hoặc bạn không có quyền truy cập vào mục đó.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'vi' },
"No se ha encontrado ningún elemento con el ID proporcionado o no tienes permiso para acceder a él.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'es' },
"No se ha encontrado ningún elemento con la ID proporcionada o no tienes permiso para acceder a él.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'es_419' },
"Nessun elemento trovato con l'ID specificato o non disponi di autorizzazioni per accedervi.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'it' },
"Det gick inte att hitta någon post med angivet ID eller så saknar du behörighet för att få åtkomst till den.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'sv' },
"Er is geen item met de opgegeven id gevonden of je hebt geen toestemming om het item te openen.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'nl' },
"Nenhum item com o ID fornecido foi encontrado ou você não tem permissão para acessá-lo.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'pt' },
"Impossible de trouver l'élément correspondant à cet identifiant. Vous n'êtes peut-être pas autorisé à y accéder.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'fr' },
"No s'ha trobat cap element amb aquest identificador o no teniu permís per accedir-hi.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'ca' },
"Элемент с заданным кодом не найден или у вас нет прав доступа к нему.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'ru' },
"Nebyly nalezeny žádné položky se zadaným ID nebo nemáte oprávnění k nim přistupovat.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'cs' },
"Item dengan ID yang diberikan tidak dapat ditemukan atau Anda tidak memiliki izin untuk mengaksesnya.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'in' },
"指定された ID のアイテムは見つからなかったか、アクセスする権限がありません。": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'ja' },
"Не вдалося знайти елемент із зазначеним ідентифікатором. Або у вас немає дозволу на доступ до нього.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'uk' },
"Verilen kimliğe sahip öğe bulunamadı veya bu öğeye erişme iznine sahip değilsiniz.": { ref: NORMALIZED_ERRORS.NO_ITEM_WITH_GIVEN_ID_COULD_BE_FOUND, locale: 'tr' },
Another option might be use other Google Apps Script services instead on DriveApp
like the Advanced Drive Service or calling the Google Drive API by using Url Fetch Service (for details on this option see Tanaike's answer but this will not make your code smaller or easier to read.