It can if all the following are true:
1) You file Chapter 11 or Chapter 13
2) The value of the home is less than the first mortgage amount
3) You complete the plan and make all payments
1. Determine the current value of your home
The following would be acceptable: 1) A recent appraisal 2) A comparative mortgage analysis from a realtor 3) A broker's price estimate from a realtor 4) Zillow.com appraisal (although these tend to give values from a few months ago rather than current value)
2. Determine if you qualify for bankruptcy
Obviously consulting an attorney is one of the best ways to determine if bankruptcy is an option or how feasible it is. People with extremely high income may not benefit much from even stripping a second mortgage off. Also, low income individuals may not have enough income to make the required payments in a Chapter 13 plan.
3. File for bankruptcy
There may be a lot of benefits to filing bankruptcy but there are also detriments to doing so. Consult an attorney to see if this choice is beneficial to you.