What if a lecturer has to use the bathroom while on stage?
Ideally, you use the bathroom before lecturing which should prevent you from needing the bathroom during the lecuture. In cases where you are unwell, I find it best to let the class know ahead of time to tell them you are unwell and might need to suddenly excuse yourself, but that you will be back.
Regardless of if you have told the students in advance, if you must excuse yourself, do it politely and tell them you will be back in a few moments.
for my own classes, I prepare with anticipation: 1) an exercise that students could complete while I am away from the Classroom or 2) show an instructional video and ask students to fill a questionnaire at the end to evaluate their comprehension of the presentation.
If there is no need to use these resources, then I just left them as assignment for next class.
Ideally, in our 21st century, every teacher should be able to record their own classes in video. In case of an unexpected emergency, students watch this lesson's recording, at least in that day.
A plausible reason is if the instructor becomes ill, and this manifests partway through a lecture.
In this case, the only thing they can do is politely explain that they are unwell.
If a teaching assistant is on hand, they may be able to take over the lecture. If not, they may choose to invite the students to use the room and time remaining for self instruction. At the university level, students should, as a group, be able to fill in the blanks for a missed half lecture.
In either case, a follow up email indicating that the next class either will or will not precede as scheduled is probably a good idea. This may include information on a time, or times, when the professor will be available to provide clarification on the subjects that were unexpectedly omitted. It should probably not include the details of the illness, unless it is sufficiently serious as to merit inclusion to explain why the professor is changing mid-semester.