What you describe is more like my experience when half-awoken in the middle of the night. That's when I'll hold adamantly to some complete bit of nonsense ("Really, this does make sense!") while my wife smiles and nods and tries to get me to turn over and go back to sleep. I often remember the event afterward and can't think why I thought I was making sense.
In contrast, when I'm falling asleep (and I assumed this was more what the parent was talking about) I'll suddenly realize that there have been one or several strands of nonsense running in my head for what seems like some time. Sometimes the strands seemed like reasonable trains of thought until I attended to them, sometimes they're just imagined dialog of other people (experienced as mentally overheard instead of consciously imagined) or something else.
But to become aware of them (and to be aware of them as nonsense) in the falling asleep case isn't to snap out of the state. The state continues often until I'm asleep, and a kind of metacognition appears over it with the realization that my thoughts don't make any sense and drawing the conclusion that I'm in the process of falling asleep. Except the original state is probably better described as semi- or sub-cognition.
It's nice to know a couple other people have similar experiences.
I'm not aware of any connection in myself between throwing an exception when almost asleep and being mindful of my emotional state and its effects while awake. (Except perhaps the correlation that I'm more mindful generally now than a few years ago, and the going-to-sleep thing might be a last-couple-years phenomenon. I don't remember it for sure before then.)
I do find that using programming metaphors (e.g., throwing an exception) for my mental processes is almost always misleading.