Cannot use __try in functions that require object unwinding fix

Move __try/__except upper in call hierarchy

void test() {
    myClass m;
    __try
    {
        m.run();
    }
    __except (GenerateDump(GetExceptionInformation())){}
}
int main()
{
    test();
}

Result: Error C2712 Cannot use __try in functions that require object unwinding ...

But:

void test() {
    myClass m;  
    m.run();
}
int main()
{
    __try
    {
        test();
    }
    __except (GenerateDump(GetExceptionInformation())) {}
}

Result: OK


Anyway I would suggest you move the code within __try/__except to an own function then call it, that way the stack unwinding occurs in the other function.

e.g.

void loop()
{
  __try  { loopimpl(); }
  __except(EXCEPTION_EXECUTE_HANDLER) {};
}

void loopimpl()
{
  while (true) { ... }
}

Tags:

C++