I sometimes say cheerfully "Oops! Little/young ears are listening. New topic!" If I act like 'oh, we all forgot little so and so, and here we are, blabbing away', I think it gives people a moment to save face. This draws less attention to the situation than if I said "could you please not talk about such and such"... which is a good conversation to have, if you can, at another time. If you have a repeat offender, let them know prior to the outing "You know, Johnny's been really concerned about death and scary things happening. Those conversations are upsetting for him. He'd love to tell you, however, about......" and give them some pointers.
I do edit myself quite a bit, but I have family members that don't. Some I love, but cringe inwardly when they speak around my son. I just try to answer any questions he has later on, but yeah, I totally understand your point. Just yesterday at a restaurant, two guys at the table next to us dropped so many F-bombs in the space of an hour, I was surprised my ears weren't blue when we left. I'm not a prude, but I was hoping Santa would bring them some new words this Christmas.:) The seemed to have run out of expressive language other than profanity and 'people screwing people over' stories. ugh.