title: How to deal with noexcept in Visual Studio
body: <p>I'm trying to create a custom exception that derives from <code>std::exception</code> and overrides <code>what()</code>. At first, I wrote it like this:</p>
  
  <pre><code>class UserException : public std::exception
  {
  private:
      const std::string message;
  public:
      UserException(const std::string &amp;message)
          : message(message)
      {}
  
      virtual const char* what() const override
      {
          return message.c_str();
      }
  };
  </code></pre>
  
  <p>This works fine in VS2012, but it doesn't compile in GCC 4.8 with <code>-std=c++11</code>:</p>
  
  <blockquote>
    <p>error: looser throw specifier for ‘virtual const char* UserException::what() const’</p>
  </blockquote>
  
  <p>So I add <code>noexcept</code>:</p>
  
  <pre><code>virtual const char* what() const noexcept override
  </code></pre>
  
  <p>This works fine in GCC, but it doesn't compile in Visual Studio (because VS 2012 doesn't support <code>noexcept</code>):</p>
  
  <blockquote>
    <p>error C3646: 'noexcept' : unknown override specifier</p>
  </blockquote>
  
  <p>What is the recommended way to deal with this? I want the same code to compile with both compilers and I'm using C++11 features, so I can't compile with different <code>-std</code>.</p>