You cannot resit an exam in an attempt to get a better exam. Only those who obtain a mark between 4 and 6.9 are eligible for reassessment.
If it turns out that you did fail and as a result are not eligible for entry to honours the following may be useful to you which is available at
http://www.st-andrews.ac.uk/students/ad ... s/#HonoursQ: I didn't get into Honours, what should I do?
A: If you haven’t met the published requirements for entry to Honours, and have appropriate grounds, you may appeal the Honours entry decision. The appeal procedure can be found in Appeals, complaints and discipline, Honours entry for students who did not get the required grade is entirely at the discretion of the School and you should contact the School as soon as possible. You should explain why you failed to meet the requirements, and how you would prevent similar problems in the future.
You will not be permitted to repeat modules in order to attain higher marks, but you may wish to change your Honours subject. If you do wish to discuss changing your degree structure, or for advice on not getting entry to Honours, contact the Pro Dean (Advising). Please note that the Pro Dean is not a route of appeal.
Dependant on how many credits you have, (since you say you were doing well before this one exam) perhaps you might be able to trail credits into honours. When the results come out, and if you did not get the results you expect, I'm sure that either your School or the Registry office will be able to provide you with further guidance on this, if applicable.