An article titled "Lose Homes, Pay More Tax" by Jonathan Glater, published in the May 30, 2008 edition of the New York Times, accurately described a little-known oddity of our tax laws (described in the article as a "tax bomb"). If a lender forgives or writes off debt (same thing), the amount forgiven can be treated as taxable income by the IRS. So, for instance, if you have a second home (not your primary residence) and you lose it to foreclosure or even a short sale, you will be taxed on the shortfall to the lender. Fortunately, loans made to acquire or improve primary residences are excluded from this rule for tax years 2007 through 2009.
What the Times article left out -- strangely, seeing as so many bankruptcy lawyers were quoted -- is that there are two exceptions to the tax bomb. If you are insolvent at the time of the debt forgiveness, you will also be forgiven your tax liability. And, here's the kicker: If you file bankruptcy prior to the debt forgiveness (read: foreclosure) the bankruptcy will not only hold off the foreclosure (at least temporarily), but also discharge the debt, so there's nothing to forgive and no income to tax.
Insolvency can be difficult to prove after the fact, but there is no doubt about the bankruptcy exception. Although many people shy away from bankruptcy, it can be a marvelous remedy when dealing with the possibility of foreclosure. It's beyond my comprehension why that point wasn't made.