- Should you pass exceptions by value or by reference?
- Will a catchstatement catch a derived exception if it is looking for the base class?
- If two catchstatements are used, one for base and one for derived, which should
come first? - What does catch(...)mean?
- What is a breakpoint?
Exercises ........................................................................................................
- Create a tryblock, a catchstatement, and a simple exception.
- Modify the answer from Exercise 1, put data into the exception along with an
accessor function, and use it in the catchblock. - Modify the class from Exercise 2 to be a hierarchy of exceptions. Modify the
catchblock to use the derived objects and the base objects. - Modify the program from Exercise 3 to have three levels of function calls.
5.BUG BUSTERS:What is wrong with the following code?
#include “stringc.h” // our string class
class xOutOfMemory
{
public:
xOutOfMemory( const String& where ) : location( where ){}
~xOutOfMemory(){}
virtual String where(){ return location };
private:
String location;
}
int main()
{
try
{
char *var = new char;
if ( var == 0 )
throw xOutOfMemory();
}
catch( xOutOfMemory& theException )
{
cout << “Out of memory at “ << theException.location() << endl;
}
return 0;
}
This listing shows exception handling for handling an out-of-memory error.
750 Day 20