24

Consider the following class:

class Xyz {
    public int count;

    public void numZero (int[] x) {
        // Effects: if x == null throw NullPointerException
        // else return the number of occurrences of 0 in x
        int count = 0;
        for (int i = 1; i < x.length; i++) //we have a bug here
            {
            if (x[i] == 0)
            {
                count++;
            }
        }

        this.count = count;
    }
}

I'm trying to wrap my head about what Fault, Error and Failure really mean.

Fault

From what I've come to understand, a Fault in this context would be a flaw in the code's written logic. So in this case the Fault would be the fact that the code instructs the computer to start iterating over all elements of v with a start index of 1 instead of the expected 0.

Error

When running the above method, we always get an Error but in once instance (when v.length == 0), as what we really want is to iterate over all elements of x, but since we're starting with i = 1, that is not really happening.

With an empty vector as input, as we don't enter the for loop, so our incorrect code isn't run, meaning that the Error doesn't happen, and everything happens as should in theory.

Failure

Since our code has a Fault that in execution-time will almost always manifest in a Error, we only have a Failure when we effectively see the incorrect output.

Assuming that an Error effectively happened in my program, we only have a Failure if it is in some way visible to the outside world. That is, had I private int count; instead of public int count; I'd never ever have an Error in my class (of course it'd be the most useless class ever!). Is this right?

Is everything I said correct or am I erring in something?

Thanks

3
  • 1
    This belongs at english.stackexchange.com Jun 12, 2011 at 18:27
  • ...or sqa.stackexchange.com :)) Jun 12, 2011 at 21:31
  • 8
    @Hans: that must certainly be a joke, right? Jun 14, 2011 at 8:40

6 Answers 6

36
  • Failure: A difference from the expected result. This is the problem you observe.
  • Fault: The cause of the failure.
  • Error: The mistake which caused the fault to occur. e.g, typos.

An example of failure, fault and error.

pre: param is an integer.
post: returns the product of the param multiplied by 2.

1. int double (int param) {
2.   int result;
3.   result = param * param;
4.   return result;
5. }

• A call to double(3) returns 9, but the post condition says it should return 6.
• Result 9 represents a failure.
• The failure is due to the fault at line 3, ( "* param" is used instead of "* 2")
• The error is a typo, ( someone typed "* param" instead of "* 2" by mistake).

Why give three different labels for a "Bug"?

They help communicate how precisely you know what the problem is.

Saying "failure" means you know something is wrong but don't know the cause.
Saying "fault" means you know the cause, but don't know why the fault occurred.
Saying "Error" means you know why the fault occurred; e.g.: The coder was distracted by a firetruck passing by.

You could ask, "But why did the person make a typo?" But that gets into into human factors and out of the scope of the question.

Source: Zhen Ming (Jack) Jiang - EECS 4413, Software Testing, York University.

7
  • 4
    Real world scenario: "I tried using my app but it failed to show my username when after I logged in. I ran the regression tests and debugger to find the fault at line 142 of the Authentication class. The error I made was forgetting to un-comment a line of code that returns the user name after logging in. Dec 24, 2017 at 22:13
  • I think, the example illustrates the difference between error and fault not very clearly. Superficially examining it, my reaction is "But of course the fault is because someone by mistake introduced it. Currently a developer is responsible for doing a correct change to the source code, and if it ended up being wrong, it is his mistake". After thinking more carefully, I came up with a scenario, that faulty line of code was originally fine, and but someone changed the line's input making it faulty. So in this case the mistake and the fault probably is distinguishable.
    – Alexey
    Sep 8, 2019 at 17:16
  • 1
    I think I agree the explanation could be more clear. Fault it what is wrong with the code. Error is why the coder coded it incorrectly. e.g: The coder was distracted an typed the wrong thing. Fault does not say anything about why the code went wrong. Error has the why's attached to it. Sep 8, 2019 at 22:08
  • 2
    Do I see it correctly that you and mouviciel have exactly switched definitions of error and fault? Could you give some examples for the distinction between fault and error? Apr 22, 2020 at 6:09
  • 1
    Fault is the thing that is wrong with your code. i.e: * instead of + or something. Error is what the programmer did wrong. They typed the wrong key. In most cases the fine grained definitions are not necessary. Sep 25, 2020 at 16:57
15

First, a failure occurs whenever the actual service delivered by a system deviates from its expected service. Note that since even specifications can go wrong, the definition does not rely on them.

Second, an error is the part of the system state that may lead to a failure. The state of the system can go wrong but never reach the output, thus not lead to a failure.

Third, a fault is the cause of an error. It can be a design fault, a cosmic ray or whatever. If, as you point out, the fault is not activated, no error is produced.

Take a look at the basic concepts and terminology of dependability for more information.

3
  • Looks like you clarified some misunderstandings that I had with this. Thanks.
    – Brandon
    Feb 8, 2015 at 20:54
  • 2
    Do I see it correctly that you and e.g. kiwicomb123 have exactly switched definitions of error and fault? Could you give some examples for the distinction between fault and error? Apr 22, 2020 at 6:08
  • @MartinThoma as stated in following paper a fault causes an error, so i think mouviciel is right here Jun 22, 2021 at 15:44
8

enter image description here

Error is a deviation from the actual and the expected result. It represents the mistakes made by the people.

Faults are the result of an error. It is the incorrect step or process due to which the program or the software behaves in an unintended manner

Bug is an evidence of Fault in a program due to which program does not behave in an intended manner

Failure is an inability of the system or components to perform its required function. Failure occurs when Faults executes

Defect is said to be detected when Failure occurs.

7

There are a plurality of different definitions, the one I personally prefer is the following:

Fault -> Error -> Failure

Fault: The verified or hypothesized cause of an error (malfunctions, external interference, design errors).

Error: The manifestation of a fault within a program or data structure (difference between actual output and expected output).

Failure: The event that occurs when an error reaches the service interface, altering the service itself (leads to the inability of a system or component to perform required function according to its specification).

3

The Error in Error/Fault/Failure refers to the human error that introduced the problem. The human error was the incorrect thinking that caused the user to create an incorrect for statement in your example.

Errors are hard to measure or understand. It is difficult in many cases to know what the developer was thinking when the made the error that introduced the fault. That is why they like to differentiate between error and fault. We can see that there is a fault in the code, but it is hard to know why the error was created. It could be that the code was correct, and then during a subsequent change, the for loop was changed.

I always remember that an Error by a programmer leads to a fault in the code that results in a failure for the user. Not all errors result in a fault. Not all faults result in failures.

1
  • “an Error by a programmer leads to a fault in the code that results in a failure for the user. Not all errors result in a fault. Not all faults result in failures.” great point!
    – Huan
    Dec 11, 2021 at 4:31
2

The software Fault refers to a bug in the code. And it is DURING the software activity.

While software Failure is when the system misbehaves. This is observed LATER than a fault.

Fault may be the cause for a Failure. Fault is "WHAT" and Failure is "WHEN".

Those are only fundamentals, but still I hope that it sheds some light on the matter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.