title: Problem throwing and catching custom exceptions in C++
body: <p>I've created the class <em>Someting</em> which throws an exception <em>SomethingException</em> (SomethingException inherits from std::exception) when it fails to instantiate. the problem is I can't catch <em>SomethingException</em> as such (I had to do a dirty trick to catch it).</p>
  
  <p>There is somewhere in the program where it executes:
  <strong>This doesn't work</strong>, the exception is not caught and the program crashes.</p>
  
  <pre><code>try{
      Something* s = new Something();
  }
  catch (SomethingException* e){
      std::cerr&lt;&lt;e.what();
  }
  </code></pre>
  
  <p>In contrast this <strong>does</strong> work (exception is caught and the correct message shown) but I really have the feelin I shouldn't be doing this</p>
  
  <pre><code>try{
      Something* s = new Something();
  }
  catch (std::exception* e){
      SomethingException* e2 = (SomethingException*) e;
      std::cerr&lt;&lt;e.what();
  }
  </code></pre>
  
  <p>Because the pointer is casted I can only make this work if and only if one type of exception is thrown. The moment I need to catch various types this won't work.</p>
  
  <p>Is there a way to caught a custom exception in a more correct way?</p>
  
  <p>Edit:</p>
  
  <p>The exception is thrown as follows</p>
  
  <pre><code>//...
  throw new SomethingException ("Errormessage"); //Custom exception constructor
  //...
  </code></pre>
  
  <p>The declaration of Something::Something() is</p>
  
  <pre><code>Something::Something() throw(...)
  </code></pre>
  
  <p>Using the declaration</p>
  
  <pre><code>Something::Something() throw(SomethingException)
  //or
  Something::Something() throw(SomethingException*)
  </code></pre>
  
  <p>Throws a lot of warnings (Warning C4290)</p>