Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6185139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:39:37+00:00 2026-05-24T01:39:37+00:00

std::exception requires that its constructor be throw() . Yet std::runtime_error accepts a std::string as

  • 0

std::exception requires that its constructor be throw(). Yet std::runtime_error accepts a std::string as its argument, which indicates that it’s storing a std::string somewhere. Therefore, an assignment or copy construction has to be going on somewhere. And for std::string, that’s not a nothrow operation.

How then does runtime_error::runtime_error meet throw()?

(For context, I’m implementing an exception type, and want to store a few std::strings from the call site, and I want to do it correctly…)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:39:38+00:00Added an answer on May 24, 2026 at 1:39 am

    (Here’s the same thing in a minimal-ish testcase.)


    runtime_error::runtime_error(string const&) doesn’t need to meet throw().

    It doesn’t inherit from or override exception::exception(), and by the time string‘s copy constructor is invoked, exception::exception() has completed.

    If copying the string were to throw an exception, this would unwind runtime_error::runtime_error(string const&) and then, I suppose, invoke exception::~exception().


    It’s hard to directly show that there is no requirement of a derived ctor to meet a base ctor’s exception specifier, but it is strongly implied by the following passage (which describes how the base’s destructor is invoked, rather than passing the exception into the base constructor):

    [2003: 15.2/2] An object that is partially constructed or
    partially destroyed will have destructors executed for all of its
    fully constructed subobjects, that is, for subobjects for which the
    constructor has completed execution and the destructor has not yet
    begun execution.
    Should a constructor for an element of an automatic
    array throw an exception, only the constructed elements of that array
    will be destroyed. If the object or array was allocated in a
    new-expression, the matching deallocation function (3.7.3.2, 5.3.4,
    12.5), if any, is called to free the storage occupied by the object.

    The only passage which comes even close to the scenario you presumed (and which I initially presumed) is the following.

    [2003: 15.4/3] If a virtual function has an exception-specification,
    all declarations, including the definition, of any function that
    overrides that virtual function in any derived class shall only allow
    exceptions that are allowed by the exception-specification of the base
    class virtual function.

    But clearly exception::exception() is not a virtual function, and clearly runtime_error::runtime_error(string const&) does not override it.

    (Note that this scenario would apply for a virtual destructor; accordingly, you can see that, in libstdc++, runtime_error::~runtime_error() is throw()).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm convinced at this point that I should be creating subclasses of std::exception for
There are some articles concluding never throw an exception from a destructor, and std::uncaught_exception()
std::map<std::string, int> m; // Can I make assumption that m[NoSuchKey] will return 0? std::cout
Or, "how do Russians throw exceptions?" The definition of std::exception is: namespace std {
What is the difference between std::runtime_error and std::exception ? What is the appropriate use
I've created the class Someting which throws an exception SomethingException (SomethingException inherits from std::exception)
Why does std::stack::pop() not throw an exception if the stack is empty and there
Standard C++'s std::exception::what() returns a narrow character string. Therefore, if I want to put
void MyGlWidget::initializeGL() { try { throw std::exception(); } catch(...) { QMessageBox::critical(this, tr(Exception), tr(Exception occured));
I have a classes: struct Policy_1 { void signalFailure() { throw std::exception(); } };

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.