When a foreclosure happens on your home due to missed mortgage payments you do have an option of getting out of the foreclosure and keeping your home.
To keep your home once foreclosure starts you will need to pay in full all the missed mortgage payments and penalties and the foreclosure costs of the bank.
Before the foreclosure even starts you should contact your bank and see what your options are on getting the missed payments to them to keep the foreclosure from happening in the first place.
Usually you can miss from 3 to 4 mortgage payment and then the bank will start foreclosing on you so contact the bank ahead of time before the foreclosure process and try to work something out.