You're supposed to enjoy the journey, not hyper focus on the destination. If the journey is not fun, the destination is not worth it, especially since you may never even get there in the first place.
In your example, if studying and acing your exam gives you more happiness in the long run (despite less happiness in the short term), it's worth it to suffer a bit now and study. If acing your exam doesn't give you more happiness in the long run, then compare it against the happiness you get if you don't ace it, and make a decision.