Programming with C++ Exceptions
ABSTRACT In pre-standard C++, the most widely used error indication technique is by returning an error code. Unfortunately, some function such as constructors, destructors, and overloaded operators do not have a return code or use the return value for purposes other than error indication. It is difficult to report failure of a constructor in a reliable way, because inevitably we must put the responsibility for error recognition into the user’s hands, who might forget to check for failure and attempt to access the "zombie" object that results from a failed construction. By and large, classic error handling is unreliable and error-prone. The language feature of exceptions solves this problem and provides a uniform means for error indication and error handling. The benefit of using exceptions is substantial, yet there are trade-offs to consider. Exception handling adds a whole new dimension of design issues and programming techniques to C++. How do we design exception classes? How do we use exceptions handling in practice? How do we program in presence of exceptions? What do we have to do in order to make programs behave nicely even in presence of exceptions? What is exception safety? Naive use of exception handling might lead to resource leaks, dangling pointers, and program crashes. How do we avoid such pitfalls? This lecture suggests answers to these and other questions. |
| PREREQUISITES | |
| ------------------------------------------------------------------------------- | |
Level: |
intermediate |
Duration: |
1.5 - 3.0 hours |
Prerequisites: |
Attendants should be familiar with the concept and language constructs of exception handling in C++. Practical experiences with exceptions is not required. |
Presented at: |
Object Expo Europe, London, UK, June 1998 Object Developers Group Meeting, New York, NY, August 1998 OOP 1999, Munich, Germany, January 1999 TOOLS, Santa Barbara, CA, August 1999 C++ World, Miami, FL, December 1999 DevWeek Europe, London, UK, February 2000 |
If you are interested to hear more about this and related topics you might want to check out the following seminars or skim through some further reading: |
|
Seminars Reliable C++ 3-day seminar (open enrollment and on-site) |
Slides Object Developers Group Meeting, New York, NY, August 1999 TOOLS, Santa Barbara, CA, August 1999 C++ World, Miami, FL, December 1999 DevWeek Europe, London, UK, February 2000 |