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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:58:56+00:00 2026-05-28T04:58:56+00:00

I just asked this question . In short, when you throw from a win32

  • 0

I just asked this question. In short, when you throw from a win32 timer callback, the exception doesn’t appear to go anywhere. It seems to be surreptitiously handled by Windows somewhere.

OK well thats a problem. The OTHER side of the problem is that destructors don’t seem to be getting called when this exception IS thrown. In the following code, for the std::vector of CFoo, the only time “~CFoo” is output is when the temporaries in GetFooVect are destructed and when the rValue is copied to fooVect. The contents of fooVect are NOT destructed.

This is my worst nightmare. I use RAII pretty heavily. I lean pretty heavily on my destructors to cleanup appropriately.

class CFoo
{
public:
    ~CFoo() {printf(__FUNCTION__ "\n");}
};

std::vector< CFoo > GetFooVect()
{
    std::vector< CFoo > rValue;
    rValue.push_back(CFoo());
    rValue.push_back(CFoo());
    rValue.push_back(CFoo());
    return rValue;
}

VOID CALLBACK Timer(HWND hwnd,
    UINT uMsg,
    UINT_PTR idEvent,
    DWORD dwTime)
{
    // My destructors aren't called?
    std::vector< CFoo> fooVect = GetFooVect();

    // I'm destroyed
    CFoo aFoo;

    throw FooExcept();
    printf("Also Here\n");
}

I’ve tried recreating this by simply throwing/catching C++ exceptions (ie removing the win32 timer callback variable) and the vector of CFoo’s destructs just fine. For some reason, destructors are NOT being called here for things in vectors. What gives? Is there a logical explanation for this, or is it just weird, or both?

  • 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-28T04:58:57+00:00Added an answer on May 28, 2026 at 4:58 am

    You should never, ever allow am exception to propagate across a C API boundary (like the SetTimer callback). C code (and the Windows API functions) know nothing about C++ language exceptions. You cannot rely on such code to propagate your exceptions.

    Your callback should catch all C++ language exceptions before returning and handle the exceptions appropriately. If you need to somehow communicate the exceptions to the rest of your application, you need to do so yourself.

    (Someone else here may be able to explain in detail what is happening in this case, but the short answer is that you can’t rely on C code to do the right thing in the presence of a C++ language exception, because it has no idea what a C++ language exception is.)

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

Sidebar

Related Questions

I just asked this question . Which lead me to a new question :)
I have just asked this question an hour ago but with regards to IE8
I asked this question yesterday, and at the time it was just what I
This question has been asked a lot but everywhere the answers fall short. I
(In case this seems familiar: I asked a different question similar to this one
I think this question is best asked with a small code snippet I just
I just asked this question about using a regular expression to allow numbers between
Can someone explain to me why this code prints 14? I was just asked
I know this has been asked thousands of times but I just can't find
I know this has been asked different ways several times, but I'm just not

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.