When one has to go to the bathroom

Hisham bin Urwah narrated from his father, (Urwah) from Abdullah bin AI-Arqam.:
 
He (Urwah) said: "While standing for the prayer he (Abdullah bin Al-Arqam) took a man by the hand leading him forward, he (Abdullah) was in front of the people, and he said: 'I heard Allah's Messenger say: "When standing for the prayer and one of you finds that he has to relieve himself then let him relieve himself first."
 
[Jaami' Al-Tirmidhi Hadith No. 142]

 

وَهُوَ قَوْلُ غَيْرِ وَاحِدٍ مِنْ أَصْحَابِ النَّبِيِّ صلى الله عليه وسلم وَالتَّابِعِينَ ‏.‏ وَبِهِ يَقُولُ أَحْمَدُ وَإِسْحَاقُ قَالاَ لاَ يَقُومُ إِلَى الصَّلاَةِ وَهُوَ يَجِدُ شَيْئًا مِنَ الْغَائِطِ وَالْبَوْلِ ‏.‏ وَقَالاَ إِنْ دَخَلَ فِي الصَّلاَةِ فَوَجَدَ شَيْئًا مِنْ ذَلِكَ فَلاَ يَنْصَرِفْ مَا لَمْ يَشْغَلْهُ
 
More than one Companion of the Prophet [sallallaahu alayhi wa sallam] and those who followed them acted on this. Ahmad and 'Ishaaq both said: A person should not begin to pray while he needs to relieve himself [whether it be urine or feces].

And both of them said that if he has began praying and then finds that he needs to relieve himself, then he should break the prayer as long as the need to relieve himself does not preoccupy him [away from concentrating on the prayer].