title: Throw catch in namespaces implementation
body: <p>I'm trying to implement a division program with a namespace. I've been really confused as to what to do, as the scope of the assignment is very broad. Could anyone please look at the code and explain why I my throw, catch statement won't catch non integer characters.</p>
  <p>It throws the exception when the denomintor is equivalent to 0, but It's not throwing the exception when characters are entered. For example when i input &quot;abc&quot; the program crashes. Could someone also explain a bit about namespaces also please? thank you</p>
  <p>Should i be using pointers?...</p>
  <p>Namespace File:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;cstdlib&gt;
  
  using namespace std;
  
  namespace dataChecks
  {
    /*
     * parameter numerator
     * parameter denominator
     * returns the double quotient of integer division
     * throws an exception if denominator == 0
     */
   //  bool isvalidInt(string str)
  
  
    double quotient( int numerator, int denominator)
    {
       if(denominator == 0)
        throw new string(&quot;divide by zero!&quot;);
       return static_cast&lt;double&gt;(numerator)/denominator;
     }//end quotient()
  
  
    /*
     * parameter str  - the string to evaluate
     * returns true if the string can be parsed
     *   into a valid int
     */
     bool isvalidInt(string str)
     {
       int start = 0;
       int i; //index of one character in the string
       bool valid = true;  // assume a valid string
       bool sign = false;  // assume no sign
  
       if (str.length()==0)    // if the length of the string is 0
           {
          valid = false;      //set valid to false
          }
  
       if ((str.at(0) == '+')||(str.at(0) == '-'))  // if the first character is '-' or '+'
       {
           sign = true;
           start= 1;      //set sign to true and start to 1
       }
  if ((start &amp;&amp; str.length()) == 1)  // if there is not at least one character after the sign
      {
          valid = false;  //set valid to false
      }
  i = start;
  while( i &lt; str.length() )// check if each character in the string is a digit - isdigit(str.at(i))
      {
          if (isdigit(str.at(i)) == false)
          {
              valid = false;      // if a character is not a digit, set valid to false
          } i++;       // return valid;
      }
  return valid;
    }
  
     /*
      * gets a string from the keyboard
      * throws an exception if the string cannot
      *   be parsed into a valid int
      * otherwise returns the int represented by the string
      */
  
     int getAnInt()
    {
  bool notanint = true;
  string svalue;
  
  while (notanint)
  {
    try
    {
      // get a string from the
      cin &gt;&gt; svalue;
      // if it is not a valid int throw an exception]
  
      if (isvalidInt(string (svalue)) == false) throw svalue;
    }
    catch (string e)
    {
  
      cout&lt;&lt; &quot;Invalid integer [ &quot; &lt;&lt; e &lt;&lt; &quot; ] - Please reenter: \t&quot;;
      // print an error messagecout &lt;&lt; &quot;Invalid integer [ &quot; &lt;&lt; e &lt;&lt; &quot; ] - Please reenter: &quot;;
          continue;
      // send control back to the while statement
    }
    notanint = false;
  }
  return atoi(svalue.c_str());  // convert to an integer
     }
  </code></pre>
  <p>Test File:</p>
  <pre><code>/*
   * CSIS1600
   * checkDivisionDemo.cpp
   * divide by zero exception
   * uses personal namespace dataChecks
   */
  
   #include &lt;C:\\CSIS1600\\MyCPPUtils\\dataChecksNamespace.cpp&gt;
   #include &lt;iostream&gt;
  
   using namespace dataChecks;
   using namespace std;
  
  int main()
  {
     int number1; // user-specified numerator
     int number2; // user-specified denominator
  
     cout &lt;&lt; &quot;Enter two integers (end-of-file to end): &quot;;
  
     // enable user to enter two integers to
      while ( cin &gt;&gt; number1 &gt;&gt; number2 )
      {
    // try block contains code that might throw exception
    // and code that will not execute if an exception occurs
    try
    {
       double result = quotient( number1, number2 );
       cout &lt;&lt; &quot;The quotient is: &quot; &lt;&lt; result &lt;&lt; endl;
    } // end try
    catch ( string *str )
    {
       cout &lt;&lt; &quot;Exception occurred: &quot;
          &lt;&lt; *str &lt;&lt; endl;
    } // end catch
   //     try
   //    {
   //        bool validint1 = isvalidInt(number1, number2);
   //    }
   //     catch ()
         cout &lt;&lt; &quot;\nEnter two integers (end-of-file to end): &quot;;
      } // end while
  
     cout &lt;&lt; endl;
   } // end main
  </code></pre>