(Throwing Exceptions from a catch) Suppose a program throws an exception and the ap- propriate exception handler begins executing. Now suppose that the exception handler itself throws the same exception. Does this create infinite recursion? Write a program to check your observation.

What will be an ideal response?


No, this would not create an infinite recursion; instead the program would be termi-
nated abnormally, because there is no handler for TestException thrown at line 18.
The second exception (i.e., the one from the catch block) would be caught by an en-
closing try...catch (if there were one) or the program would terminate.

```
#include
#include
using namespace std;

// class TestException definition
class TestException : public runtime_error
{
public:
// constructor specifies error message
TestException::TestException( const string& message )
: runtime_error( message ) {}
}; // end class TestException
```
```
#include
#include "TestException.h"
using namespace std;

int main()
{
// throw same exception from catch handler
try
{
throw TestException( "This is a test" );
} // end try
catch ( TestException &t )
{
cerr << t.what() << endl;
throw TestException( "This is another test" );
} // end catch

return 0;
} // end main
```
This is a test
abnormal program termination

Computer Science & Information Technology

You might also like to view...

__________ methods are the actions that are applied to ARs to regulate access to the enterprise network.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

A(n) ______________ determines the size and positioning of nodes in the scene graph.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Pinterest is free for ________ use

Fill in the blank(s) with correct word

Computer Science & Information Technology

________ that moves across the screen is one example of a JavaScript effect

Fill in the blank(s) with correct word

Computer Science & Information Technology