error handling for doc.