I think my pediatrician caused me to become erect on purpose, and asked me if I knew what it was and if it had happened before. It was very embarrassing because the answer to both of those questions was yes.
I only recall two instances when a doctor has ever touched my penis. Those two doctors where urologists who touched my penis long enough to squeeze the meatus in order to open the urethra for a quick look inside it. My primary care physicians have never touched my penis but concentrate on the testicles and scrotum palpating for lumps and hernias. I don't recall ever becoming erect during any of these exams. To the contrary, I "turtle up" and shrivel due to the cold, sterile environment. Sometimes I wish for an erection thinking that it would be less embarrassing than the less than masculine appearance of my penis and scrotum when they are shriveled up in these situations.
My doctors have very much respected my modesty, but there was once instance where I got erect, and the doctor ignored that it was hard.
I remember a pre-teen physical erection. My pants were unbuttoned/unzipped and lowered to my knees. When she pulled my underwear down to mid thigh I was completely erect. She focused on testicle exam and feeling inguinal creases extensively while ignoring my penis altogether.
I normally get an erection when my doctor examines my penis and he just does the examination the same as if I didn't have one. He has never commented about it or anything.
In a real exam I can only recall being erect one time and that was when I was in my early teens when even a windy day it could make me erect! However, the doctor said nothing and just went ahead and did the hernia check but never touched my penis. However, I do remember being so totally embarrassed and completely mortified that it happened. I am sure my face must have been red with embarrassment!
Most of the times I'm already semi or fully erect right from the start while undressing, and it would be quite obvious for the doctor to notice even before my briefs have to come of as well. On only one or two occassions during a school physical, the doctor made a comment about it like 'that seems to be working quite well'. However in most cases the doctor would say nothing and simply act as if it was normal to have an erection. He always examined my erect penis thoroughly by having a good look at it and feeling my balls, shaft and glans while moving my foreskin several times up and down. During my first couple of school physicals as a teen I actually thought that having an erection during the procedure was required for the doctor to do this part of the exam properly. Although I still felt embarassed for being naked in front of the doctor, having an erection did not add much to that because of this thought. Only later after hearing class mates talk about the school physicals I realized that it was actually not common or appropriate to get fully erect during the physicals. Still I could not control it and that added to the feeling of excitement as well as embarrassment during my physicals. Growing up through my teens and becoming more aware of my own sex and body only added to those feelings. Next to that I also became aware that despite my obvious (and he must know awkward) erection, the doctor often seemed to have a preference to have a good look at it multiple times. Most of the times he would lower my briefs midway of the exam for a short inspection and then later he would remove them completely and I would remain totally naked for the remainder of the exam. From my perspective it seemed unnecessary for the sole purpose of the exam, but being fully exposed twice by the doctor while erect gave me the impression that he liked to watch me and that actually made me feel proud of my body and show it off.