Can LLMs Learn from Previous Mistakes? Investigating LLMs' Errors to Boost for Reasoning