A foreclosure will virtually destroy your credit which is why you should avoid it any way that you can. There are so many things you can do to avoid foreclosure and some are listed below;
For instance, you can make arrangements with your lender so that you can sell the house on a "short sale" where your lender agrees to take whatever the house will sell for and then you would get a "release of mortgage" to record at your county recorder's office to show the termination of your mortgage.
You will need to have a Realtor help you do this as it is not easy at all. To do a short sale, typically the lender will want you to have the property on the market for at least 90 days before they will consider giving you a "Deed in Lieu of Foreclosure," following the short sale.
Under certain hardship circumstances you can work out a "Deed in Lieu of Foreclosure" with your lender where you give it back to them. Clearly they do not want properties back in these hard economic times but there again, you may have a good reason to go in this direction.
You should contact a real estate attorney and find out if you have a "Right of Redemption" on your mortgage which will give you up to a year to get caught up on your mortgage.
You have some potential solutions. When you default on your mortgage payments and go into foreclosure, you will not be able to buy another house for at least 4 years or more. So, in order to protect the roof over your and your family's heads you must always pay your mortgage first even if it means not paying someone else such as credit cards.