To qualify for the tax-free treatment, the taxpayer will need to have filed for bankruptcy and the debts canceled at the order of the bankruptcy court.
For taxpayers faced with foreclosure or short-sales, it might be more advantageous to utilize the mortgage exclusion for acquisition debt and the insolvency exclusion for home equity and other types of canceled debt before considering a bankruptcy case.
Filing for bankruptcy can generate several tax implications, so for more details see the Bankruptcy Tax Guide (Publication 908) on the IRS Web site.

