When a person thinks too much without taking any action, he/she is over thinking. In fact, when you are always examining similar thoughts over and over again rather than taking necessary action, you are over thinking.
As in this situation, over thinking about what has already happened with you in the past, has spoilt your present exam and will ruin your future result as well. So, when over thinking is so fatal, why should one think so much?
Know that what has happened, has happened. It is undone and unchangeable, so why to spend time and energy thinking about what is not in your hands.
Know that exam is a matter of 3 hours, and you have to give your hundred percent in the time period. You can anyways go back home and talk to that particular friend of yours regarding what is bothering you and must be certainly bothering him or her too.
Know that people look up to you. Your family especially your parents want to see you happy and well-settled in life. Similarly, you had worked hard the whole semester or probably the whole year, for this day, then why to waste this precious time to prove your capability to the world?
Remember if you perform well in the exam, not only you will be happy, but even that friend of yours whom you love so dearly, that he or she is constantly coming in your mind, will be extremely annoyed with you knowing that you spoilt your exam because of him. In that case, she or she will feel guilty. I believe you do not want this, right?
All the very best!!