Many people have a headache when talking about C ++ code. They often feel that editing long and messy code is not starting, well, after reading this article, you will no longer be troubled by complicated code problems. I hope you can get help.
The code for the C ++ program is as follows:
- # Include
- # Include
- Using std: cout;
- Using std: endl;
-
- Struct prediction_registration
- {
- Prediction_registration * prev;
- DWORD handler;
- };
-
- Prediction_disposition myHandler (
- _ EXCEPTION_RECORD * ExcRecord,
- Void * EstablisherFrame,
- _ CONTEXT * ContextRecord,
- Void * DispatcherContext)
- {
- Cout<<"In the exception handler"<< Endl;
- Cout<<"Just a demo. exiting ..."<< Endl;
- Exit (0 );
- Return ExceptionContinueExecution; // It will not run to this
- }
-
- IntG_div=0;
-
- Void bar ()
- {
- // Initialize a prediction_registration Structure
- Prediction_registration reg ,*Preg=®
- Reg. handler= (DWORD) myHandler;
-
- // Obtain the "Header" of the current Exception Handling Link"
- DWORD prev;
- _ Asm
- {
- Mov EAX, FS: [0]
- Mov prev, EAX
- }
- Reg. prev= (Prediction_registration *) prev;
-
- // Register!
- _ Asm
- {
- Mov EAX, preg
- Mov FS: [0], EAX
- }
-
- // Generate an exception
- IntJ=10/G_div; // exception, Division by zero Overflow
- }
-
- Int main ()
- {
- Bar ();
- Return 0;
- }
The above is my summary of the C ++ program code. I will continue to update the code, so stay tuned!