Failure allows you to learn that making mistakes is contrary for you to learn how to avoid making mistakes like that again. You can't avoid something if you don't even know where it's coming from, so you need to make the mistake of not avoiding it to know how to avoid it next time.