Responding to Difficult Moments in the Classroom

How do you manage those moments in the classroom when a student makes a problematic comment? Or when you learn after the fact of a comment you didn’t hear but other students did, or that you yourself made? How can these moments be used to advance student learning?