title: Difference between runtime errors and logic errors
body: <p>I've been studying C++ for two months and now I'm studying the chapter in my book (Programming Principles and Practice using C++) about errors. But after studying the first pages I have a question: <strong>what is the difference between a runtime error and a logic error?</strong> According to my book a runtime error is an error found by checks at runtime and we can further classify runtime errors as: </p>
  
  <ul>
  <li>hardware error / operating system error</li>
  <li>errors detected by a library</li>
  <li>errors detected by user code (what is user code?)</li>
  </ul>
  
  <p>while logic errors are simply errors found by the programmer looking for the causes of erroneous results. </p>
  
  <p>I thought I had understood this difference but then an example provided by the author created doubts in me. This is the example:</p>
  
  <pre><code>#include "std_lib_facilities.h"
  
  int area(int lenght, int width) // calculate area of rectangle 
  {
      return lenght * 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 area1 = area(x, y); 
      int area2 = framed_area(1, z); 
      int area3 = framed_area(y, z); 
      double ratio = double(area1) / area3; 
  }
  </code></pre>
  
  <p>Here is what the author briefly says about this example : </p>
  
  <blockquote>
    <p>the calls of the function area() and framed_area() lead to negative
    values, representing areas, being assigned to area1 and area2. Should
    we accept such erroneous results? But before answering these question
    look at the calculation of ratio, in the calculation of ratio area3
    will be 0 and the division with 0 will lead to hardware-detected error
    that terminates the program with some cryptic message. This is the
    kind of error that you, or your user, will have to deal with if you
    don't detect and deal sensibly with runtime errors.</p>
  </blockquote>
  
  <p>What I don't understand here is why a negative value used as an argument for a function that calculates the area is treated as a runtime error, isn't it just a logic error? I thought that runtime errors were only errors due for example by dividing a number by 0 and other special cases. Am I wrong or am I just misunderstanding something? <strong>What is the real difference between logic errors and runtime errors?</strong> Could you show me some little examples? </p>