For me the difference is whether it's a one-off or a recurring incident.
A one-off, you apologize and excuse yourself immediately - leave with no explanation, claim a bathroom break, fake an injury, whatever - no worries. Embarrassing, yes, and inappropriate, yes, but I realize it happens...