Take a deep breath, realize it's not over and move on.
Being a perfectionist and raised in a household where grades ruled all, I know what it's like to panic at the thought of failure. As a college student who spends their life studying and trying to obtain a degree in what you'd like to have a career in, grades pretty much mean the world. But a failing one isn't the end of it either.
Should you worry about it constantly? No. Panic at first? Maybe a little. But then you need to take a deep breath, realize it's not over and move on.
"Midterms" and "finals" are two words dreaded by every college student ever. You study and study. Spend nights staying up with that energy drink and notes sprawled across your desk. You have to get a good grade on this exam or your grade will fall. Great. But now you're sleep deprived and the next morning can barely make out what is written on the exam paper.
Here's some advice:
Don't panic about a test the night before. Don't worry about all the little things that you could get wrong. You'll set yourself up for failure. It's a self-fulfilling prophecy. Study, but take breaks and go to bed with enough time to get quality sleep. If you don't know the thing by now, you're not going to learn it on a sleep-deprived energy-drink-fueled study cram.
If you do happen to get a low grade on your midterm or recent quiz and your grade drops, just sit back for a minute and examine where you went wrong, what you need help with and most importantly FIX IT.
You can't solve a problem by staring at it and not moving.
If you do nothing about a situation, the problem will continue to grow. Don't let it.
You may have an F or a D in your class around midterms. Ask your professor what you can do about it. See if you can attend study sessions. Ask questions or make sure when you study, you're actually focusing and not just staring blankly at the page.
If none of that works, go to your academic advisor. Ask what can be done and how an F in that class affects your GPA. Ask if there's a way to take it over the summer or find an easier course along the same type of path. Take lower level math, for example.
And make it happen.