You refinanced and took out some of the loan money for luxuries. The idea of this exception is to rescue homeowners trapped in a home that is no longer worth what they paid for it to the extent that the mortgage balance consumes all the equity. Thus the mortgage money must be used in an attempt to add value to your home. That is not the case if you refinanced, taking out not only enough money to pay off the old mortgage, but even more to treat yourself to a vacation, new car, boat, etc. This also applies even if you used the money to pay down debt! That trap can spring if your refinancing bank made the loan contingent on your paying off credit card debt!
You took out a home equity line of credit and did not use the money for home improvements. This is a corrollary to the first exception. If you took out the money to do a kitchen or bath upgrade, finish the basement, or add a room, then fine. However, if it was for debt consolidation or that second honeymoon, that doesn't count!
It is not your residence, but a vacation home or investment property. This exception is to protect homeowners, not house owners, so if it wasn't your primary residence for at least two of the past five years, you are out of luck. Many New Jerseyans bought vacation properties at the shore during the real estate boom. Unless they move in and stay for awhile, they will have to wait to sell or face the tax man.
You own a multimillion dollar home. Sorry, the IRS doesn't feel sorry for rich people. The exception has a cap of $2 million on the taxable forgiven income. Thus there is a limit to the amount of protection you have from tax forgiveness income.
As you can see, there is good news and bad news tax-wise if you lost a property to foreclosure or sold it short. If you had that happen to you in the last tax year, you need to consult with a tax professional to make sure you do not pay taxes unnecessarily. If one of the above exceptions applies, you may have to talk to a bankruptcy attorney to get relief.