Add a new handle function for error handling