It is said on the Internet that memcpy is written in C language and there is no exception handling mechanism.
But it seems that seh can handle it.
Seh ("structured exception handling"), that is, structured exception handling-a powerful weapon provided by the (Windows) operating system to program designers to handle program errors or exceptions.
In the vs2010 compiler, the project property-> C ++-> code generation-> enable C ++ exception settings are as follows: Yes, but seh exceptions (/EHA)
The following text comes from: http://www.cppblog.com/mzty/archive/2006/09/22/12824.html
Seh is a function provided by windows and has nothing to do with development tools. It is worth mentioning that VC encapsulates seh in try catch finally, and C ++ can also encapsulate _ Try {}__ using t () {}and _ Try {}__ finally {}. so when you create a C ++ try block, the compiler generates a s e h _ t r y block. A c ++ c a t c h test turns into a s e h exception filter, and the code in c a t c h becomes the code in the s e h _ e x c e p t block. In fact, when you write a C ++ throw statement, the compiler generates a call to the r a I s e x c e p t I o n function of Wi n d o W S. The variable used for the t h r o W statement is passed to r a I s e x c e p t I o n as an additional parameter.
A simple example of using seh
If you want to implement a completely strong application, the program needs to run 7 days a week, 2 4 hours a day. In today's world, software has become so complex that there are so many variables and factors that affect program performance. I think if we don't need S E h, it is impossible to implement a completely strong application. Let's first look at a sample program, that is, the runtime function s t r c p y of C:
Char * strcpy (char * strdestination, const char * strsource );
This is a simple function. How does it cause a process to end? If the caller passes n u L (or any Invalid Address) to one of these parameters, s t r c p y causes an access exception and causes the entire process to end.
Using s e h, you can build a completely strong s t r c p y function:
Char * robuststrcpy (char * strdestination, const char * strsource)
{
_ Try
{
Strcpy (strdestination, strsource );
}
_ Handler T (exception_execute_handler)
{
// Nothing to do here
}
Return (strdestination );
}
All this function does is place calls to s t r c p y in a structured exception handling framework. If s t r c p y is successfully executed, the function returns. If s t r c p y causes an access exception, the exception filter returns e x c e p t I o n _ e x e c u t e _ H a n d l e r, causing the thread to execute the exception handler code. In this function, the processing program code does not do anything. R o B U S T R C P Y is only returned to its caller and does not cause the process to end.
Seh-exceptions about capturing memcpy