开发者

function try block. An interesting example

开发者 https://www.devze.com 2023-01-19 09:04 出处:网络
Consider the following C++ program struct str { int mem; str() try :mem(0) { throw 0; } catch(...) { } }; int main()

Consider the following C++ program

struct str
{
       int mem;
       str()
       try
          :mem(0)
       {
               throw 0;
       }
       catch(...)
       {
       }
};

int main()
{
       str inst;
}

The catch block works, i.e.开发者_如何学JAVA the control reaches it, and then the program crashes. I can't understand what's wrong with it.


Once the control reaches the end of the catch block of function-try-block of a constructor, the exception is automatically rethrown. As you don't catch it further in main(), terminate() is called. Here is an interesting reading: http://www.drdobbs.com/184401316

0

精彩评论

暂无评论...
验证码 换一张
取 消