c++ - Difference between runtime errors and logic errors -
I am studying C ++ for two months and now I use my book (using programming principles and practice Reading C ++) About errors but after studying the first pages I have a question: What is the difference between a runtime error and a logic error? According to my book, runtime error is an error from check on runtime and we can do the following
While logic errors simply found bugs by programmers in search of reasons for inaccurate results
I thought I Understood the difference but In an example provided by the author, I doubt there is an example:
#include "std_lib_facilities.h" int area (integer number, integer width) // the area of rectangle Calculation {return length * width; } Int framed_area (int x, int y) // calculate area within frame {return area (x - 2, y - 2); } Int main () {int x = -1; Int y = 2; Int z = 4; Int Zone 1 = Area (X, Y); Int area 2 = framed (1, z); Int Zone 3 = Pharmedry (y, z); Double ratio = double (region1) / region3; } The author briefly says about this example:
The function area () and the framed () call leads to negative values Are assigned to regions, region 1 and area 2. Should we accept such wrong results? But before answering these questions, in the calculation of the ratio, the ratio 3 will be calculated as 3 and divisible by 0 will result in hardware discovered error which will end the program with some secret message. This is an error that you, or your user will have to deal with, if you do not know and does not deal with sensitivity errors with runtime errors.
I do not understand here why a negative value is used as a logic for a function which calculates the field as a runtime error Is it not just a logic error? I thought that runtime errors are only due to errors, for example, by dividing the number by 0 and other special cases, am I wrong or am I mistaken? What is the real difference between logic errors and runtime errors? Can you show me some less examples?
A runtime error may be valid: eg. Some file containing garbage data or some incorrect human input, or some lack of resources (some other memory, disk space complete, broken hardware, network connection failure)
A logic error (or unsuccessful emphasis ....) is defined by the definition of some bugs in the always program, e.g.
See the header:
: Defines the type of object thrown in the form of an exception to report errors in this category. In violation of the program's internal logical, such as logical pre-condition or class inventions.
: This class defines the type of items thrown as an exception to the report of those errors which can only be identified during the runtime.
If you formulate the specificity of your program formally (with the help of using ACSL), then you (and probably correct) logic errors; But you should be careful about runtime errors but you may also have bugs in the details.
Read about it and look for some other ideas.
Comments
Post a Comment