finish error-handling mechanism