Hey there,
I can definitely relate to this. I've broken down in the middle of exams and have had numerous panic attacks before and after my exams. It is kinda difficult to "get over" this because it's something I found difficult to control, especially during stressful situations. One thing that kinda calmed me down during the exam was to just keep moving on if I don't know how to do a question. The times I broke down mid-exam where my 3U exams and I either: couldn't figure out the question or I was trying to solve the question but something wasn't working out, which ended up me being like to myself: why isn't this working out? Why am I so dumb? (fun fact: that question where my working out wasn't going the right way, it turned out that there was a typo in that question). The more I spent on that question, the more stressed I got. Because of that, I would leave some space to do the next question so when I go back, I could at least have a fresh set of eyes (this actually worked when I couldn't figure out how to do a proof for a congruent/similar triangles question).
Another thing I would suggest is to actually take the time to breathe, just like what Angelina said. I used to dismiss this but it was actually really important, especially when I had a panic attack before my Paper 1 trials. It was difficult for me to use my reading time effectively when my breathing hasn't evened out, so take the time to breathe slowly. Also, straighten your posture when you're trying to re-adjust your breathing. Naturally, we would want to curl up in a ball but that's not really opening up our lungs. My school counsellor did recommend to use the wall to adjust our posture and breathe slowly, but in an exam situation, align your back to your chair and sit up straight to open up your lungs. When you breathe slowly, your heart rate will also calm down.
And also, take a bottle of water with you into the exam. I never took my bottle into the exam until Paper 1 trials (yes, the same occasion when I had a panic attack beforehand). It actually helps you take a "break" during the exam. Usually, when I got stressed doing homework, the best way to lower my stress levels is to either do something different (as addressed previously) or go for a walk and refill my cup. Obviously, we can't really go for a walk during the exam so bringing in a water bottle and taking small sips is the next best thing. Disclaimer: I wouldn't recommend taking huge gulps of water so you won't have to go to the bathroom too often. So yeah, I'd highly recommend bringing in a drink bottle (and this is also coming from someone who gets anxious over the thought of using the bathroom, which then ends up triggering my need to go to the bathroom. Weird, I know).
Hope this helps!