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++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.


1 answer

Sort by: Most helpful
  1. Castorix31 91,886 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."

    Was this answer helpful?

    0 comments No comments

Your answer

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