//*************************************************************** // From the book "Win32 System Services: The Heart of Windows 98 // and Windows 2000" // by Marshall Brain // Published by Prentice Hall // // Copyright 1995, by Prentice Hall. // // This code demonstrates a try-finally pair. //*************************************************************** // term.cpp #include #include VOID main(VOID) { CHAR *ptr; // point the pointer to an // invalid address ptr=NULL; __try { cout << "No problems." << endl; } __finally { if (AbnormalTermination()) cerr << "Cleaning up after exception." << endl; else cout << "Cleaning up after normal" << " execution." << endl; // clean up } __try { cout << endl << "Make problems." << endl; // attempt to assign a value // to the location pointed // to by the pointer *ptr=5; } __finally { if (AbnormalTermination()) cerr << "Cleaning up after exception." << endl; else cout << "Cleaning up after normal" << " execution." << endl; // clean up } }