When something goes wrong, explain it clearly to your child. Go over what happened and then work out together what he or she might be able to do differently in the future.
Teach your child with love how to learn from a mistake.
First things first, calm your child down. Next be an active listener, showing both understanding and reassurance. Then comes the teaching. You want to explain to your child what he or she should do so as not to make the same mistake again.
If the occurrence was emotionally charged, wait to teach until you think your child is truly ready to be able to learn the lesson.