Implemented an error-handling mechanism