I recently saw a patient for his post-hospitalization visit after a heart attack, and noticed he was upset. He was not upset with me, our office, or about his hospital experience. He was angry at himself.

“I did everything right,” he muttered, shaking his head.

“What do you mean?” I asked.

“I never smoked, I exercise nearly every day, I take my cholesterol medication and control my blood pressure. How could I have failed to protect myself?”

Patients can sometimes be wrought with guilt because illness occurs despite proper adherence to preventive guidelines. Doctors often spend a lot of energy encouraging behaviors that lower risk. But like every medical intervention, preventive care has its limitations, and they may not be fully explained.

In truth, none of us has complete control of our health outcomes. There are many genetic and environmental factors that influence disease that we do not fully understand. And then there is just plain luck, to which no blame can be assigned.

The purpose of preventive care is to lower your risk for disease, not to eliminate any possibility of it. Science tells us that people who eat a healthy, balanced diet, exercise regularly, control their blood pressure, and take a statin (when indicated) are much less likely to have a heart attack, or die of one. Yet we do, as with the patient I recently saw, see exceptions. This is no one’s failure.

“I’m sorry that this happened. I think your healthy habits helped you recover, and may have limited the severity of your heart attack,” I said, trying to reassure the patient.

“I didn’t think of it that way,” he replied.

“The fact that you had a heart attack does not mean you are a failure,” I added.

We discussed this further, and I think he left believing that his efforts were worthwhile. I also encouraged him to complete his other preventive care, including screening for colon cancer.

A similar sense of frustration has surfaced around COVID-19 prevention. People who are observing all safeguards and precautions — even some fully vaccinated people — are still occasionally becoming infected with the COVID-19 virus. Masking and hand washing substantially reduce the risk of infection, and most cases in those who are vaccinated are far less severe than in the unvaccinated population.

Once again, the same adage applies: Prevention will substantially lower your risk, and a “breakthrough” case is not a prevention failure.

A favorite quote of mine from vaccine pioneer Louis Pasteur is, “Chance favors the prepared mind.” By this he was referring to the way careful study and diligent preparation can help inspire creative insights. In health maintenance and prevention, it’s good to remember that chance also favors the prepared body.

Jeffrey Millstein is a primary-care physician and medical director for patient experience-regional practices at Penn Medicine.