In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "C++ Code example Analysis". In daily operation, I believe many people have doubts about C++ Code example Analysis. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "C++ Code example Analysis". Next, please follow the editor to study!
So v should call their destructor. But suppose that during this call, the destructor of the second Widgets throws another exception. Now there are two exceptions in the activity at the same time, which is too much for C++ code parsing. If such two simultaneous activity exceptions occur under very coincidental conditions, the execution of the program will terminate or cause undefined behavior.
In this case, an undefined behavior is thrown. Similarly, using any standard library container (for example, list,set), any container in TR1, or even an array, can cause undefined problems. You don't have to be a container or an array to get into trouble. The aborted or undefined behavior of a program is the result of an exception thrown by the destructor.
This is true even if you are not using containers or arrays. C++ doesn't like destructors that throw exceptions. This is easy to understand, but what if your destructor needs to perform an operation that may fail and throw an exception? For example, suppose you parse C++ code with a database connection class:
Class Widget {public:. ~ Widget () {...} / / assume this might emit an exception}; void doSomething () {std::vector v;.} / / v is automatically destroyed here
To ensure that customers don't forget to call the close of the DBconnection object, it's a reasonable idea to set up a resource management class for DBConnection and call close in its destructor. Such a resource management class will be discussed in a future article, but here, it is sufficient to think that the destructor of such a class looks like this:
Class DBConn {/ / class to manage DBConnection public: / / objects... ~ DBConn () / / make sure database connections {/ / are always closed db.close ();} private: DBConnection db;}; it allows customers to program like this: {/ / open a block DBConn dbc (DBConnection::create ()) / / create DBConnection object / / and turn it over to a DBConn / / object to manage... / / use the DBConnection object / / via the DBConn interface} / / at end of block, the DBConn / / object is destroyed, thus / / automatically calling close on / / the DBConnection object
It would be nice to parse the C++ code successfully, but if the call causes an exception, DBConn's destructor will spread the exception, that is, it will leave the destructor. This creates a problem because the destructor throws a hot potato.
At this point, on the "C++ code example analysis" study is over, I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.