How do we check before hand if a document exists when we have a ID

Certified Senior Developer
Is there a way to find if the document is already in the system, before we use the document() function with the attributes. Suppose we store the DocumentID in DB and while retrieving the document if the document was deleted from the system, how do we make sure the availability of the document in the system. If we use the document function, it will throw error saying document doesn't exist or been deleted and script task gets stuck.

OriginalPostID-233463

  Discussion posts and replies are publicly visible