One candy bar won't hurt your baby. Eating a lot of sweets and carbs will in the long run if you are diabetic. But your doctor will explain all that with you. I wouldn't worry about what she is telling you.
I get irritated when anyone butts into my business like that. As long as you are eating an otherwise healthy diet, a chocolate bar every now and then shouldn't hurt you. The problems with sweets and carbs come when you overdo it and eat them all the time. You're human, you're going to want something sweet from time to time. If it's not a staple of your daily diet and you are otherwise staying away from it, I say treat yourself.