In education circles, this is known as a teachable moment, the lesson being to think before you act.