Toothache can be caused by a cavity but it may be due to other reasons. One simple thing to try is to gently floss around the affected tooth because sometimes a tooth can be pushed painfully out of place by impacted food. If your toothache persists then please see your dentist as soon as you can.
People may experience tooth sensitivity or pain when consuming something very hot or cold and your dentist will be able to suggest suitable solutions or treatments for reducing this sensitivity. Other times a tooth may develop tiny microfractures or cracks that will open when you bite down, allowing food or bacteria to enter the crack potentially causing dental pain and infection.
Persistent toothache is always a sign that something is wrong so please see your dentist as soon as possible. The sooner you seek treatment, the sooner we can get rid of your pain and better the chances of saving the tooth.