The Intersection of Divorce and Bankruptcy

From Which Should I File First: Divorce or Bankruptcy?

I am going to file for divorce from my husband in the near future. I pay the mortgage payments out of my bank account. He pays nothing toward the mortgage. I am moving out and will not continue paying the mortgage. He says that he will let the house go into foreclosure because he says he cannot afford to pay the mortgage. Can I file bankruptcy before the house goes into foreclosure? If so, will they still be able to come after me for the house? I don’t want the foreclosure to go against my already bad credit. Thanks so much.