title: Can't catch exception std::stoi
body: <p>Whenever I input anything other than an integer, I was hoping for the catch block to execute but instead I get this error: </p>
  
  <blockquote>
    <p>Unhandled exception at 0x002D0C39 in A03.exe: Stack cookie instrumentation code detected a stack-based buffer overrun. occurred</p>
  </blockquote>
  
  <p>which takes me to:</p>
  
  <blockquote>
    <p>Exception thrown at 0x76D44192 in A03.exe: Microsoft C++ exception: std::invalid_argument at memory location 0x0116D83C.</p>
    
    <p>Unhandled exception at 0x000608B9 in A03.exe: Stack cookie instrumentation code detected a stack-based buffer overrun.</p>
  </blockquote>
  
  <p>I've tried varieties of catch blocks and exceptions with the same error. Can someone tell me what I'm doing wrong? Thank you!</p>
  
  <p>Here is the code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>int main() {
      while (true) {
          std::string input;
          int num = 0;
  
          std::cout &lt;&lt; "What number do you want to show?";
          std::cin &gt;&gt; input;
          try 
          {
              num = std::stoi(input);
              if (num &gt;= 0 &amp;&amp; num &lt; 10)
              {
                  std::cout &lt;&lt; "FILLER: This will draw the number";
  
                  exit(0);
              }
              else {
                  std::cout &lt;&lt; "FILLER: This is the else";
                  exit(1);
              }
          }
          catch (std::runtime_error e) 
          {
              std::cout &lt;&lt; e.what();
              //std::cout &lt;&lt; "That is not a valid number." &lt;&lt; '\n';
          }
      }
      return 0;
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>: Edited the exception handler, but still erroring:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>int main() {
      while (true) {
          std::string input;
          int num = 0;
  
          std::cout &lt;&lt; "What number do you want to show?";
          std::cin &gt;&gt; input;
          try 
          {
              num = std::stoi(input);
              if (num &gt;= 0 &amp;&amp; num &lt; 10)
              {
                  std::cout &lt;&lt; "FILLER: This will draw the number";
  
                  exit(0);
              }
              else {
                  std::cout &lt;&lt; "FILLER: This is the else";
                  exit(1);
              }
          }
          catch (std::invalid_argument &amp;e) 
          {
              std::cout &lt;&lt; e.what();
              //std::cout &lt;&lt; "That is not a valid number." &lt;&lt; '\n';
          }
      }
      return 0;
  }
  </code></pre>