Mounting debt. Lapsed mortgage payments. A tanking economy.

It can be enough to make you want to throw up your hands and file for bankruptcy. But bankruptcy is more than a white flag to wave at the stampede of irritated creditors. It’s a tool that, in some cases, can help you keep your home.

Are you are among those for whom bankruptcy is a reasonable tool to cope with a housing crisis? To find out, we asked attorneys, researchers and real estate experts about the two types of bankruptcy, Chapter 7 and Chapter 13. Because bankruptcy law is federally regulated, these suggestions apply across all 50 states.

Chapter 13: Putting time on the clock

Chapter 13 bankruptcy grants consumers up to five years to repay their debts. The 2005 revision of the bankruptcy code encourages Chapter 13, and it’s the most common form used by homeowners, said Katherine Porter, associate professor of law at the University of Iowa College of Law and contributor to the Credit Slips blog. Porter researches mortgage claims in consumer bankruptcies.

Use Chapter 13 to:

Catch up after a brief lapse in mortgage payments. About three of four people who file for Chapter 13 protection are homeowners, said Porter. If you’re trying to save your home from foreclosure, you’ll likely have to come up with all your delinquent payments and foreclosure fees up front. Chapter 13 allows you to spread those payments over several years.

Pay off debt from a short sale. If you sell at a $50,000 loss to avoid foreclosure, the IRS will expect you to pay taxes on that $50,000. In Chapter 13, you can distribute those payments instead of taking a major tax hit the year after you lose your home.

But Chapter 13 doesn’t allow a judge to modify your mortgage to get you out of a terrible loan. And only one in three people who file for Chapter 13 bankruptcy make it to the end of the repayment agreement, said Porter, possibly because the original agreement was unrealistic.

“Chapter 13 protection is really for the person who has an extra $200 a month to put toward repayment of their debts and who has experienced an economic shock — lost a job and found a new one, a brief illness — and has recovered,” said Porter. “For people with an exotic mortgage where the payments will continue to escalate, there’s nothing about bankruptcy that will fix that.”

Chapter 7: Debt written off for good

Unlike Chapter 13, Chapter 7 bankruptcy permanently discharges debts (except taxes and student loans), including delinquent mortgages. But that doesn’t mean you’ll avoid foreclosure. In fact, to forgive the mortgage through bankruptcy, your lender will likely have to go through foreclosure anyway to transfer the deed. That means both a foreclosure and a bankruptcy will show up on your credit report.

A better use of Chapter 7 is to get rid of credit card debt to focus your resources on your home. For that to work, you need enough money to pay your mortgage or your credit cards, but not both.

“If you’ve got a little bit of equity and are paying your mortgage on time but overwhelmed by credit card debt, bankruptcy can make sense,” said Roswell, Ga.-based Patricia Glover, who has been a bankruptcy attorney for more than 20 years.

The good news: If you can keep paying your mortgage on time after bankruptcy, you’ll buoy your credit score.

“For my clients who have gotten rid of their credit card debt, repaying their mortgage is a great way to start rebuilding their credit,” she said. “Most of my clients get back on their feet credit-wise to the same credit score they would have had if they’d never filed for bankruptcy.”