So much depends on the individual; at the various times in my life where I've been doing music lessons, it's usually been a time when the rest of my life was over-examined; I'd have given up all music if a teacher had merely suggested exams, as it was my exam-free refuge. The strange thing is, it doesn't take a catastrophe in an exam to put someone off the subject. I decided many years ago that since I was having to learn a foreign language, I'd do the job properly, and take all the exams I could, with a view to keeping it as an alternative career if needed. I stuck to my lessons for quite a while, but after the first serious exam (which I passed very respectably), I realised the exam preparation had destroyed all my enjoyment, and was undermining my love of the language. So I decided not to do any further exams - but for some reason, this also stopped me from doing more lessons. I don't know why. Moral: exams are a tool, for many people useful, but to be used with care and understanding.
As to how you sort out the after-effects of a bad exam, I don't know. There was a very insightful, and beautifully-written post here some years ago, that I cannot find. Someone was asking for advice after a fail. Someone else replied that following her failure, yes, within the next couple of days two men in grey suits and bowler hats would arrive at the door to confiscate her instrument and purge the house of any sheet music, and she would be cast out into the outer darkness and no musician would ever speak to her again. Of course, continued the respondent, this is absolute nonsense. Actually nothing has changed, certainly not her ability to play the instrument, so really she didn't need to do anything - except decide whether to bother re-taking, or just chalk it up to experience and continue.
A failure is a blow. But it's good for our fibre in the long-run. The very best people have failures in their past. To continue after a bad experience shows persistence, and persistence is more important to success (many would say) than talent alone. An exam tests you on one day only; a bad experience only means you weren't at your best that day. Be strong, look forwards, and tell the exam board to stuff it! (I hope they'll forgive me for using their own site to say so!)