Implements error handling