Safe Exercise?

Li
I have been ttc for 9 months now. In the process I have gain about 15lbs. I recently started going to the gym and I am trying to be more active so that I don't continue to gain unnecessary weight. Is it safe to exercise while ttc or while pregnant?