Most of the time we face this question in our testing interview and most of the people find it difficult to find the difference between these term even after living in the industry since long time.
Error: This is cause due to human actions like code is not following the standard, there is some mistake in syntax, or there is mistake in invocation of variable or might be there is some mistakes in which database connectivity code is faulty. These all are counted as Error.
Defect: Defect is formal name of bug and if we are tester than we would be familiar with Bug.Defects may occurs due to errors(Mistakes in code or document) that cause deviation from actual result. Once a tester find error then this is called defect and when this is acknowledge by Developer or Design team along with Manager this become Bug.
Failure: Failure are caused by environment or sometime due to mishandling of product. Suppose we are using a compass just beside a current running wire then this will not show the correct direction and this is not helping in getting the right information from the product. In the same way radiation,magnetism,Electronic field. These things not only have impact on product but also impacts its hardware also.
In other way when a defect is found by end-user then this is called failure.