Sorry to hear that.
To be honest, this is very common. Students tell me that they spend a lot of time studying for an exam and then get a poor grade on it. This really just shows that your performance in a particular field does not depend solely on the time you put into it. It depends on the way you prepare.
So, I guess I should ask: how did you prepare for this class exam?