Visual C++ 6 Unleashed

Visual C++ 6 Unleashed

By MICKEY WILLIAMS and David Bennett

Summary

In this chapter, you examined structured exception handling. You saw what exceptions are and how to handle them so that they will not force your program to come to a crashing halt. You also learned the difference between hardware exceptions and software exceptions.

Although you learned that SEH is not really intended to be used with C++ but with C, the SEH concepts carry over to what you can use with C++: C++ exception handling.

You saw how to use C++ exception handling to deal with the relationship of an application and a class member. You learned about throwing an exception and catching one.

You also looked at how to guard your code with try and then how to call exception code in the catch block after the exception is thrown. Using these keywords, you were able to recover sample programs from exception errors.

After checking out a few examples, you looked at the capabilities of multiple exception handling—how the same class can handle more than one exception. You then looked at using arguments with exceptions. You created an example that passes arguments to the class member so that the exception error can return specific information, such as the function name that caused the error and what values contributed to the exception.

You also looked at MFC error and exception handling. You briefly examined MFC macros. MFC macros were the original way to handle exception errors in early MFC versions. For MFC 3.0 and later, you can use the C++ exception mechanism.

Although all later versions of MFC support macros, it is recommended to use the C++ exception mechanism, and to use macros only to support older programs that previously used them.

Finally, you learned about MFC exception handling, which is C++ exception handling with the MFC predefined exceptions. You were briefly introduced to each predefined exception, and you explored how to generate custom exception classes.

Share ThisShare This

Informit Network