Writing Exception Handlers and Filters

Listing 26.1 is an example of code that attempts to protect itself from errors in the traditional way, by performing operations and then testing their outcomes. The code tests for both violation of the routine's protocol contract (invalid passed parameters) and system errors, such as when the system has run out of resources. Most of the time such errors will not happen, although the time spent validating the parameters can be lost thousands of times in the life of the program.

Code Listing 26.1. Traditional Use of the Windows API
 BOOL PaintTheBitmap ( HWND hWnd, HBITMAP hBitmap) { BOOL bReturnCode = FALSE; // Check passed parameters. //......................... if ( hWnd && hBitmap) { HDC hDC = GetDC( hWnd ...

Get Microsoft Windows 2000 API SuperBible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.