As far as I know, filing for bankruptcy temporarily stops the foreclosure process and allows you to get back on track with your mortgage payments. Mortgage debt is not wiped and bankruptcy courts can’t modify loan terms (e.g. reduce the amount owed). All that happens is that you’re not kicked out while your case is decided, and then you get a second chance.. If you’re behind on your payments, you can work out a 3-5 year repayment plan.
Obviously does not do you much good (long-term) if you got yourself in an option ARM or your monthly payment is 60% of your net income. But if you’re a responsible buyer, there’s light at the end of the tunnel.