Handle errors gracefully