Bankruptcy Law Questions? Ask a Bankruptcy Lawyer.
Your absolute best option is to offer a deed in lieu of foreclosure because it avoids foreclosure and a deficiency. It is a peaceful return of the property to the lender. The only catch is if the lender will accept it - which is totally up to it.
If the lender will not accept the deed in lieu, and you can't file bankruptcy before the foreclosure, you absolutely can include the deficiency in your bankruptcy when you file.
If you file bankruptcy BEFORE there is a deficiency judgment, the mortgage will simply be included in your bankruptcy and discharged accordingly - there will never be a deficiency judgment.
If you file bankruptcy, the lender will ask the court for permission to foreclose on the property - which the court will allow - and whatever the sale produces will be all of the recovery the lender will have. The remaining balance owed will simply be discharged.