Is division by zero considered error or failure? - error-handling

When my program stops working due to division by 0 then is it considered error or failure?
Error is called when a human action produces an incorrect result. Failure is when we get different result than expected. I'm just wondering if the unexpected stop from program is a error by human or failure of the program?

It is considere as an error. Or we can also called this an exception. And if u dont want to prevent this u can use exception handling.
Depending on the programming environment and the type of number (e.g. floating point, integer) being divided by zero, it may generate positive or negative infinity, generate an exception, generate an error message, cause the program to terminate.

It is a type of failure when it is in compile time but it is an error because usually this type of an error occur when the program is compiled and then executed

Related

CBMC Toy Example

I'm new to CBMC and experimenting with it. In this link here, there is a toy example for checking the function binsearch with CBMC. I decided to run the following command that they provided, just changing up the number of times the loop was unwound:
cbmc binsearch.c --function binsearch --unwind 4 --bounds-check --unwinding-assertions
It returned the following:
** Results:
[binsearch.unwind.0] unwinding assertion loop 0: FAILURE
prog.c function binsearch
[binsearch.array_bounds.1] line 7 array `a' lower bound in a[(signed long int)middle]: SUCCESS
[binsearch.array_bounds.2] line 7 array `a' upper bound in a[(signed long int)middle]: SUCCESS
[binsearch.array_bounds.3] line 9 array `a' lower bound in a[(signed long int)middle]: SUCCESS
[binsearch.array_bounds.4] line 9 array `a' upper bound in a[(signed long int)middle]: SUCCESS
Is the fact that the unwinding assertion failed because there weren't enough iterations a bad thing? From my point-of-view, it seems like the example is bug-free because the code didn't access portions of memory that it's not supposed to, but I'm not sure based on that one unwinding assertions failure. Anyone have any ideas about the safety? Does that failure matter?
Based on the --unwinding-assertion property, which checks the following:
Checks whether --unwind is large enough to cover all program paths. If the argument is too small, CBMC will detect that not enough unwinding is done reports that an unwinding assertion has failed.
I'd say that it is alerts to the possibility that there aren't enough loop iterations to make sure that the function won't access the array outside of the bounds. This means that while the function didn't violate any properties with 4, we need to check all paths before we can say that it is safe for certain.

Why am I getting this Mathematica error - "Syntax: Incomplete expression more input is needed"

I'm running this on Wolfram cloud. Here's the code
ClearAll[s,l,L,L1,M1,Mt,m,M,vym,vxm,wp,J,Meff,theta,omega]
Rr = {{Cos[theta],-Sin[theta],0},{Sin[theta],Cos[theta],0},{0,0,1}};
Wm = {0,0,omega};
This is obviously part of a larger code, but just this much is enough to create the error. If I remove any line, the error disappears. I can't for the life of me figure out where a syntax error could be in here!

MiniZinc "cannot determine bounds"

Writing my first non-trivial MiniZinc app, I keep running into the error "cannot determine bounds". How does one generally resolve this error?
In general “cannot determine bounds” means that the solver cannot determine the bounds (the domain) of a decision variable.
Using "var int" as the domain of a decision variable should be avoided if possible, since it will probably slow down the solving process. There are times where the solver can figure out the domain, e.g. in cases likes
% ...
var int: z = sum(x);
when "x" have declared domains. But, as a rule, try to define the domains.

MATLAB Genetic Algorithm "Subscripted assignment dimension mismatch" Error

When trying to use the Genetic Algorithm solver in MATLAB, I'm getting the following "Subscripted assignment dimension mismatch" error: Error Message Pastebin
Now, it says the error has to do with the fitness function at the end, but when I test my fitness function separately, it works without errors. I can also link the code for my fitness and constraint functions if that would help.
Thank you very much!
I think I see what is happening... Because one of the appendages to CDraft is inside the if, you don't always return the same length vector - i.e., you return a constraint vector the first time, it preallocates a matrix for your constraint output, then the next time round you give it back something that doesn't fit in this matrix, so you get the error.
The clue is in the error stack: at the top of the stack we have
Subscripted assignment dimension mismatch.
Error in C:\Program
Files\MATLAB\R2012b\toolbox\globaloptim\globaloptim\private\gaminlppenaltyfcn.p>i_convectorizer
(line 135)
Clearly this is not a function you've written, and inspecting your function there's nothing that should cause this error. The end of the error gives another clue
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
The ga function is reporting an error in the bit of the code that handles user-supplied constraints. It is likely that this whole bit of code (the call to the user-supplied function and other associated lines) are all within one try...catch statement that returns this error. Something like this:
try
c = userConFun(x);
if isempty(cHistory)
cHistory = zeros(length(c), 1000); % or whatever
end
cHistory(:, currentIterationIndex) = c;
catch err
error('Failure in user-supplied fitness function blah blah blah');
end
Consequently, it looks like the error came from your function, even though it occurred after your function returned.

Understanding what Fault, Error and Failure mean

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
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.
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.
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.
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).
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.
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.