In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how the C++ compiler implements exception handling, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
As there are too many programs installed in the C++ compiler, you can't upload them here, so you can get some communitysever from it and decompile it for your own use.
And reason is an excellent alternative solution. It clearly separates the normal code from the error handling code, and the program becomes very clean and easy to maintain. This article discusses how the compiler implements exception handling. I will assume that you are already familiar with the syntax and mechanisms handled by the C++ compiler. This article also provides an exception handling library for VC++. To replace the one provided by VC++ with the handler in the library, you only need to call the following function:
Struct EXCEPTION_REGISTRATION {EXCEPTION_REGISTRATION* prev; DWORD handler;}
After that, all exceptions in the program, from being thrown to stack expansion (stack unwinding), to calling catch blocks, and * until the program resumes normal operation, will be managed by my exception handling library.
Like other C++ features, the C++ standard does not specify how the compiler should implement exception handling. This means that every compiler provider can implement it in the way they think is appropriate. I'll describe how VC++ works below, but even if you use another compiler or operating system ①, this article should be a good learning material. The implementation of VC++ is based on the structured exception handling (SEH) ② of the windows system.
Struct EXCEPTION_REGISTRATION {EXCEPTION_REGISTRATION* prev; DWORD handler;}
In the discussion of this article, I think the exception is either explicitly thrown or caused by zero overflow, null pointer access, and so on. When it occurs, there is an interrupt, and then control is transferred to the operating system. The operating system will call the exception handler, the sequence of function calls starting from the location where the C++ compiler exception occurs, and carry out stack expansion and control transfer. Windows defines the structure "EXCEPTION_REGISTRATION", which enables us to register our own exception handlers with the operating system.
# include # include using std::cout; using std::endl; struct EXCEPTION_REGISTRATION {EXCEPTION_REGISTRATION* prev; DWORD handler;}; EXCEPTION_DISPOSITION myHandler (_ EXCEPTION_RECORD * ExcRecord, void * EstablisherFrame, _ CONTEXT * ContextRecord, void * DispatcherContext) {cout
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.