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 7248061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:05:18+00:00 2026-05-28T22:05:18+00:00

I have a function that can be reduced to this: void f() { static

  • 0

I have a function that can be reduced to this:

void f() {
    static MyObject o("hello");

    DoSomethingWith(o);
}

This function is called across a C API boundary, so like a good boy, I use try to catch any exceptions that are thrown before they cross the boundary and screw things up:

void f() {
    try {
        static MyObject o("hello");

        DoSomethingWith(o);
    } catch (const MyObjectException& e) {
        Message("Constructor of o failed");
    }
}

This function is called the first time and I get the message "Constructor of o failed". However, later, the function is called again, and I get the message again. I get the message as many times as f is called. I am using Visual C++ so this tells me what MSVC++ does, but not what should be done.

My question is, what should happen when the constructor of a static function variable terminates unusually (by throwing, a longjmp out of the constructor, termination of the thread that it’s in, etc)? Also what should happen with any other static variables declared before and after it? I would appreciate any relevant quotes from the standard as well.

  • 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-28T22:05:18+00:00Added an answer on May 28, 2026 at 10:05 pm

    Section 6.7 ([stmt.dcl]) of the C++11 standard states that

    The zero-initialization (8.5) of all block-scope variables with static storage duration (3.7.1) or thread storage duration (3.7.2) is performed before any other initialization takes place. Constant initialization (3.6.2) of a block-scope entity with static storage duration, if applicable, is performed before its block is first entered. An implementation is permitted to perform early initialization of other block-scope variables with static or
    thread storage duration under the same conditions that an implementation is permitted to statically initialize a variable with static or thread storage duration in namespace scope (3.6.2). Otherwise such a variable is initialized the first time control passes through its declaration; such a variable is considered initialized upon the completion of its initialization. If the initialization exits by throwing an exception, the initialization
    is not complete, so it will be tried again the next time control enters the declaration.
    If control enters the declaration concurrently while the variable is being initialized, the concurrent execution shall wait for completion of the initialization.
    If control re-enters the declaration recursively while the variable is being
    initialized, the behavior is undefined.

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

Sidebar

Related Questions

I have: void add_all_msgs(std::deque<Message>::iterator &iter); How can I make that function generic, so it
I have a function that can accept any number of arguments... const getSearchFields =
I would like to have a function that can wrap any other function call.
I have a PHP function that requires can take 3 parameteres... I want to
I have a problem with Lucene's scoring function that I can't figure out. So
How can we new primitive types in JNI. I have a function that returns
I have noticed in Java that you can have a function with object... as
I have a javascript function (function1) that checks some global variables (can the user
Does Actionscript have a built-in function that accepts a number and can return a
I have this API function: public ResultEnum DoSomeAction(string a, string b, DateTime c, OtherEnum

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.