What you have done is learnt a lesson in bonking. Thats perfectly ok. To avoid it again make sure you have plenty of fluid with you and a snack. I usually have a banana or chocolate bar. Take some money in case you need a shop. Get on your bike and ride. You will be fine.