How is the C++ exception handling runtime implemented?

后端 未结 4 860
梦毁少年i
梦毁少年i 2020-11-28 21:54

I am intrigued by how the C++ exception handling mechanism works. Specifically, where is the exception object stored and how does it propagate through several scopes until i

4条回答
  •  青春惊慌失措
    2020-11-28 22:08

    You could take a look here for a detailed explanation.

    It may also help to take a look at a trick used in plain C to implement some basic sort of exception handling. This entails using setjmp() and longjmp() in the following manner: the former saves the stack in order to mark the exception handler (like "catch"), while the latter is used to "throw" a value. The "thrown" value is seen as if it has been returned from a called function. The "try block" ends when setjmp() is called again or when the function returns.

提交回复
热议问题