Bankruptcy could help you delay foreclosure or avoid it entirely. So, if you're facing foreclosure, does that mean that you need to file bankruptcy? And if so, when?
There are ways to deal with your mortgage default that don't involve bankruptcy, some of which may be better. Whether or not bankruptcy is right for you depends on what other options are available to you and how close you are to losing your home.
If you've just defaulted, you probably have time to work toward a solution that doesn't involve bankruptcy. But if you've been served with foreclosure papers (in a judicial foreclosure state), have a sale date in the near future, and no other options, then bankruptcy could be right for you.