Chapter 4. Exception Handling
Windows Structured Exception Handling (SEH) is the principal focus of this chapter, which also describes console control handlers and vectored exception handling.SEH provides a robust mechanism that allows applications to respond to unexpected events, such as addressing exceptions, arithmetic faults, and system errors. SEH also allows a program to exit from anywhere in a code block and automatically perform programmer-specified processing and error recovery. SEH ensures that the program will be able to free resources and perform other cleanup processing before the block, thread, or process terminates either under program control or because of an unexpected exception. Furthermore, SEH can be added easily to existing code, often simplifying program logic.Chapter 2. SEH is usually confined to C programs. C++, C#, and other languages have very similar mechanisms, however, and these mechanisms build on the SEH facilities presented here.Console control handlers, also described in this chapter, allow a program to detect external signals such as a Ctrl-c from the console or the user logging off or shutting down the system. These signals also provide a limited form of process-to-process signaling.The final topic is vectored exception handling, which requires Windows XP or 2003 Server. This feature allows the user to specify functions to be executed directly when an exception occurs, and the functions are executed before SEH is invoked.
