John Dewey said this quote

Failure is instructive. The person who really thinks learns quite as much from his failures as from his successes.