The Rambam wrote in the first chapter, law 9: Just as the community fasts over its distress, so too an individual fasts over his distress. How so? If he had a sick person, or was wandering in the desert, or was imprisoned in a beit ha-asurim—he should fast for it and seek mercy in his prayer, and he says "Anenu...". And he shall not fast on Shabbatot, nor on festivals, nor on Rosh Chodesh, nor on Chanukah and Purim. Thus far his words. And even if he began to fast—he stops on these days. And only regarding the community are there days that if they began they do not stop, as I have written in siman 572, see there, but not regarding an individual (Maggid Mishneh). And the law if he vowed regarding these days was explained in siman 570, see there.
כתב הרמב"ם בפרק ראשון דין ט: כשם שהציבור מתענין על צרתן, כך היחיד מתענה על צרתו. כיצד? הרי שהיה לו חולה, או תועה במדבר, או אסור בבית האסורים – יש לו להתענות עליו ולבקש רחמים בתפילתו, ואומר "ענינו…". ולא יתענה לא בשבתות, ולא במועדות, ולא בראש חודש, ולא בחנוכה ופורים. עד כאן לשונו. ואפילו התחיל להתענות – מפסיק בימים אלו. ורק בציבור יש ימים שאם התחילו אין מפסיקין, כמו שכתבתי בסימן תקעב עיין שם, ולא ביחיד (מגיד משנה). ודין אם נדר על ימים אלו נתבאר בסימן תקע, עיין שם.