Click Here!
home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
[an error occurred while processing this directive]
Previous Table of Contents Next


CHAPTER 11
EXCEPTION HANDLING IN C++

How do I...

11.1  Utilize the exception handling mechanism to process potential error conditions?
11.2  Use the various catch constructs such as multiple catch clauses, catch ordering, and the rethrowing of exceptions?
11.3  Implement and use an exception class?
11.4  Specify exceptions that a function will throw?
11.5  Handle exceptions that are not caught or not expected?

How-To 1.7 demonstrated the use of the exception handling mechanism offered by the C++ Standard. That How-To is a basic introduction into the use of exception handling. This chapter will explore the world of exception handling in more detail.

The exception handling mechanism furnished by the Standard provides a common and standard interface for handling program anomalies. Without exception handling, error handling is performed using return values from functions and global status variables. Every developer has her own style of handling errors, leading to inconsistency among applications and library packages. In this chapter, you will see various ways to apply the exception handling mechanisms.

One word of caution about this chapter: If you are using a compiler that does not support exception handling, the examples will not compile and execute as expected. If you have been putting off upgrading your compiler, now is the time to do it.

11.1 Utilize the Exception Handling Mechanism to Process Potential Error Conditions

Error handling is an important feature for the success of an application. Invalid input, access to hardware that is not available, and other program anomalies must be tested for and handled gracefully. This How-To gives a review of the C++ exception handling mechanism. The exception handling mechanism provided by the C++ Standard is a standardized process for handling exceptions at runtime.

11.2 Use the Various catch Constructs Such As Multiple catch Clauses, catch Ordering, and the Rethrowing of Exceptions

The C++ exception handling mechanism is a very robust and standardized way to handle program anomalies. Multiple catch clauses provide a means to handle more than one exception type thrown from a try block. The ordering and rethrowing of catch clauses can be important. In this How-To, you will see how to set up multiple handlers and how to rethrow exceptions.

11.3 Implement and Use an Exception Class

The throwing of exception types can include native types such as int and char* and user-defined types. User-defined exception types provide a more robust mechanism for the capturing and reporting of exceptions. In this How-To, you will see how to declare, define, throw, and catch exception class objects.

11.4 Specify Exceptions That a Function Will Throw

Exception handling is an important feature of the C++ language. The exception handling mechanism provides a robust method for handling errors at runtime. Yet, for the developer, knowing all the exceptions a function will throw can sometimes be guesswork. Exception specifications provide a mechanism to reveal the exceptions a function will or will not throw.

11.5 Handle Exceptions That Are Not Caught or Not Expected

Although the exception handling mechanism is very robust and allows you to handle exceptions of any type, the unexpected exception is indeed difficult to handle. In this How-To, you will see how to incorporate code to manage unexpected exceptions.

11.1 Utilize the exception handling mechanism to process potential error conditions?

Problem

I need to incorporate exception handling into my programs. I have read that the C++ language Standard provides a standard facility to handle exceptional conditions at runtime. How can I get a good overview of exception handling in C++?

Technique

This How-To begins by providing a straightforward example that demonstrates various uses of the exception handling mechanism. This How-To will only scratch the surface of exception handling; the How-Tos that follow will address specific issues and advanced features of the C++ exception handling mechanism.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.