title: Creating custom exceptions in C++
body: <p>I am learning C++ and I am experiencing when I try and create my own exception and throw them on Linux. </p>
  
  <p>I've created a small test project to test my implementation and below is my exception class header file.</p>
  
  <pre><code>class TestClass : public std::runtime_error
  {
  public:
      TestClass(char const* const message) throw();
      virtual char const* what() const throw();
  };
  </code></pre>
  
  <p>The source file for the exception class is</p>
  
  <pre><code>using namespace std;
  
  TestClass::TestClass(char const* const message) throw()
      : std::runtime_error(message)
  {
  
  }
  
  char const * TestClass::what() const throw()
  {
      return exception::what();
  }
  </code></pre>
  
  <p>In my main app, I am calling a function which throws my exception and catches it in a try/catch as follows:</p>
  
  <pre><code>void runAFunctionAndthrow();
  
  /*
   * 
   */
  int main(int argc, char** argv) {
      try
      {
          cout &lt;&lt; "About to call function" &lt;&lt; endl;
          runAFunctionAndthrow();
      }
      catch (TestClass ex)
      {
          cout &lt;&lt; "Exception Caught: " &lt;&lt; ex.what() &lt;&lt; endl;
      }
  
      return 0;
  }
  
  void runAFunctionAndthrow()
  {
      cout &lt;&lt; "going to run now. oh dear I need to throw an exception" &lt;&lt; endl;
  
      stringstream logstream;
      logstream &lt;&lt; "This is my exception error. :(";
      throw TestClass(logstream.str().c_str());
  }
  </code></pre>
  
  <p>When I run I'm expecting to get the following output:</p>
  
  <blockquote>
    <p>About to call function </p>
    
    <p>Going to run now. oh dear I need to throw an exception</p>
    
    <p>Exception Caught: This is my exception error. :(</p>
  </blockquote>
  
  <p>Instead what I am getting is</p>
  
  <blockquote>
    <p>About to call function</p>
    
    <p>going to run now. oh dear I need to throw an exception</p>
    
    <p>Exception Caught: std::exception</p>
  </blockquote>
  
  <p>Notice the last line it says std::exception instead of my actual exception message "This is my exception error". </p>
  
  <p>Why is this, it works OK on Windows but on Linux it does this. </p>
  
  <p>From what I've seen on various posts what I've done is correct so what am I missing. </p>