Bankruptcy and foreclosure, both your have a huge negative affect on your credit report and will drop your credit score but foreclosure is the worst thing and borrowers try to avoid it and even files bankruptcy to avoid foreclosure.
Actually Bankruptcy is a relief tool that has been provided by the Federal Government and the bower or the consumers use it as the last resort to avoid foreclosure or the harassment from the creditors or lenders.
Foreclosure and bankruptcy has similar affect on your credit report. Foreclosure will drop your credit score by 250 to 300 points and the bankruptcy will affect your score almost the same but if a lender find out that the borrower has faced foreclosure in recent past then he may not approve a loan and even if any lenders approve a loan; the rates will be comparatively much higher. So it is better to consult with an attorney to understand minute affects of both foreclosure and bankruptcy.
As it seems that both foreclosure and bankruptcy will have similar negative credit affect and bankruptcy is a relief tool to avoid the harassment from the creditors, bankruptcy is a better option to choose but as it is previously said that bankruptcy should be the last option to choose to avoid foreclosure and the court will also check whether you are eligible to file bankruptcy or not.