Chapter 13 bankruptcy can stop a foreclosure and give you up to five years to catch up on missed mortgage payments. You keep the house only if you make every plan payment and every new mortgage payment on time. Before you file, make sure your budget can carry both for the whole plan.

Source