Endometriosis

I have endometriosis witch causes me to be infertile . I’ve been trying to have a baby for 4 years now I recently had a miscarriage and I am still trying to have a baby the doctors say I shouldn’t try cause I could put my life and the baby life in danger if I ever became pregnant I don’t really understand how ... I just need advice should I stop trying or should I keep trying ? If I keep trying what are some good medicine I should take to help me get pregnant ?