title: C++: How to pass parameters to custom exceptions?
body: <p>I have created a custom exception:</p>
  
  <pre><code>class MyIOException : public std::exception
  {
  public:
    virtual const char* what() const throw()
    {
      return "IO Exception";
    } 
  };
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class MyEmptyImageException : public MyIOException
  {
  private:
    std::string m_bucketName;
    std::string m_objectName;
  
  public:
  
    MyEmptyImageException(const std::string&amp; bn, const std::string&amp; on) : m_bucketName(bn), m_objectName(on) {}
    virtual const char* what() const throw()
    {
      std::string msg = "Empty Image : " + m_bucketName + m_objectName;
      return msg.c_str();
    }  
  };
  </code></pre>
  
  <p>And I try it like this:</p>
  
  <pre><code>int main(int argc, char** argv)
  {
    try
    {
      // ... read image
      if (image.empty)
      {
        throw MyEmptyImageException(folderName, imageName);
      }
      // ... remained code
    }
    catch (MyEmptyImageException&amp; meie)
    {
      std::cout &lt;&lt; meie.what() &lt;&lt; std::endl;
    }
    catch (std::exception&amp; e)
    {
      std::cout &lt;&lt; e.what() &lt;&lt; std::endl;
    }
    return 0;
  }
  </code></pre>
  
  <p>I am not sure if I have done it right, could you correct me, or suggest a better implementation, because I am a beginner in using derived exceptions?</p>