How use "throw" in __try __except block

drjackool 956 Reputation points
2021-02-19T09:07:28.853+00:00

Hi
I using following code:

void foo() throw(...)
{

    EXCEPTION_RECORD _ER;
    __try
    {
            if (some condition)
                AfxThrowMemoryException();
    }
    __except(GetExceptionRecord(GetExceptionInformation(), &_ER), EXCEPTION_EXECUTE_HANDLER)
    {
        // do some thing
    }
}

in function calling:

TRY
{
     foo();
}
CATCH_ALL(e)
{
  e->report();
}
END_CATCH_ALL

My problem is when throwing some exception the __except block executed instead outer try catch block

Thanks

Developer technologies | C++
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,686 Reputation points
    2021-02-19T09:25:40.633+00:00

    You can see MSDN doc : try, throw, and catch Statements (C++)
    And from try-except statementt :

    "For C++ programs, we recommend you use native C++ exception-handling: try, catch, and throw statements."

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.