handle error gracefully