Although this is not often how things are done, here is a suggestion for improving exams, whilst addressing your problem:
An exam is meant to test the ability of the student to apply what was taught in the course. If this knowledge is to mean anything "after the course", then the conditions in which the course is administered need to mirror the real world closely. This, in turn, should mean that the understanding needed to do well in the exam should not hinge on the ability to memorize (I am a big fan of "open book" exams — bring in the reference material, it cuts down on cheating), but rather the ability to synthesize and apply — two things that are very hard to get help with during a bathroom break.
The other solution is to divide the exam into a series of shorter exams — say 1 hour exams followed by a 15 minute break, followed by another hour, etc. The intermediate results are handed in before each break, so there is no point in obtaining help during the breaks. Regular short breaks will refresh the exam takers, and give them a chance to go to the bathroom if they need to.
In line with this suggestion, the idea that "people cannot concentrate on a task for more than 45 minutes" seems to be widely believed — see this for example. If that is indeed true, the above makes even more sense.
And if the exam is such a coherent whole that it is not possible to break it up (for example, it requires three hours of solid writing of a single essay) then good luck to the person who attempts to get help during a bathroom break …
In summary:
- allow the students to have reference material
- break the exam into shorter pieces
- test understanding and synthesis, not memorization