title: Getting a debug error using the function error()
body: <p>This is a direct follow-up to my last <a href="https://stackoverflow.com/q/71727416/18692517">question</a> I asked recently. I would recommend checking it before reading this.</p>
  <p><em>The text given below in blockquote and code sample is from a book called Programming: Principles and Practice using C++, Chapter 5- Errors (Under the Run-time errors section)</em></p>
  <blockquote>
  <p>So, let’s tackle the problem of argument errors with area(). We have two obvious
  alternatives:</p>
  <ol>
  <li>Let the caller of area() deal with bad arguments.</li>
  <li>Let area() (the called function) deal with bad arguments.</li>
  </ol>
  </blockquote>
  <blockquote>
  <p>Let’s try the first alternative (“Let the user beware!”) first. That’s the one we’d
  have to choose if area() was a function in a library where we couldn’t modify it.
  For better or worse, this is the most common approach.
  Protecting the call of area(x, y) in main() is relatively easy:</p>
  </blockquote>
  <pre><code>if (x&lt;=0) error(&quot;non-positive x&quot;);
  if (y&lt;=0) error(&quot;non-positive y&quot;);
  int area1 = area(x, y);
  </code></pre>
  <blockquote>
  <p>Really, the only question is what to do if we find an error. <strong>Here, we have called a
  function error() which we assume will do something sensible. In fact, in
  std_lib_facilities.h we supply an error() function that by default terminates the program
  with a system error message plus the string we passed as an argument to error().
  If you prefer to write out your own error message or take other actions, you catch
  runtime_error (§5.6.2, §7.3, §7.8, §B.2.1).</strong> This approach suffices for most student
  programs and is an example of a style that can be used for more sophisticated
  error handling.</p>
  </blockquote>
  <p>I tried to run the code sample in Visual Studio and <a href="https://i.stack.imgur.com/ooZqt.png" rel="nofollow noreferrer">this</a> is what I was greeted to by a window of Microsoft C++ Runtime Library under practice34.exe:</p>
  <blockquote>
  <p>Debug Error!
  Program:</p>
  </blockquote>
  <pre><code> C:\Users\..\source\repos\practice34\x64\Debug\practice34.exe
  </code></pre>
  <blockquote>
  <p>abort() has been called
  (Please Retry to debug the application)</p>
  </blockquote>
  <p>I have options to either Abort, Retry or Ignore.</p>
  <p>Retrying gives me this:
  <code>C:\Users\..\source\repos\practice34\x64\Debug\practice34.exe</code> (process 9020) exited with code -2147483645.</p>
  <p>Now I suppose, I should get a simple error in console using my string argument I passed in the error function. But instead I'm getting this. I have no idea why this is happening.</p>