In the USA this is taxed as if the loan was forgiven - so one side or the other pays the tax.
There are ways to abuse the bankruptcy laws, but they are difficult and time consuming and usually not worth it.