title: Exception Handling in C++ by throwing a string
body: <p>My program is following : (on linux)</p>
  
  <pre><code>// Ex. 2 of Exception Handling
  // Here divn() raises the exception but main() will be the exception handler
  
  #include&lt;iostream&gt;
  using namespace std;
  
  int divn(int n, int d)
  {
      if(d == 0)
          throw "Division by ZERO not possible ";
  
      return n/d;
  }
  
  main()
  {
      int numer, denom;
      cout &lt;&lt; "Enter the numerator and denominator : ";
      cin &gt;&gt; numer &gt;&gt; denom;
      try
      {
          cout &lt;&lt; numer &lt;&lt; " / " &lt;&lt; denom &lt;&lt; " = " &lt;&lt; divn(numer,denom) &lt;&lt; endl;
      }
      catch(char *msg)
      {
          cout &lt;&lt; msg;
      }
      cout &lt;&lt; "\nEnd of main() \n ";
  }
  </code></pre>
  
  <p>/*it should throw the exception and provide the given error message when we put denominator as 0. the output I get when i enter the denom as 0 is as follows :</p>
  
  <blockquote>
    <p>administrator@ubuntu:~/FYMCA/CPP_class$ g++ prog110.cpp
    administrator@ubuntu:~/FYMCA/CPP_class$ ./a.out Enter the numerator
    and denominator : 12 0 terminate called after throwing an instance of
    'char const*' Aborted (core dumped)</p>
  </blockquote>
  
  <p>How do I solve the problem?</p>