(Stack Unwinding) Write a program that throws an exception from a deeply nested func- tion and still has the catch handler following the try block enclosing the call chain catch the excep- tion.

What will be an ideal response?


```
2 #include
3 #include
4 using namespace std;
5
6 // class TestException definition
7 class TestException : public runtime_error
8 {
9 public:
10 // constructor specifies error message
11 TestException::TestException( const string& message )
12 : runtime_error( message ) {}
13 }; // end class TestException
```
```
#include
#include "TestException.h"
using namespace std;

void f()
{
throw TestException( "TestException" );
} // end function f

void g() { f(); } // end function g

void h() { g(); } // end function h

int main()
{
try
{
h();
} // end try
catch ( TestException &t ) // catch any exceptions that occurred in h
{
cerr << "In main: Caught " << t.what() << ’\n’;
} // end catch

return 0;
} // end main
```

Computer Science & Information Technology

You might also like to view...

weak_ptrs should be used in any situation where you need to ________ the resource but don’t want to assume any management responsibilities for it.

a. delete b. copy c. observe d. move

Computer Science & Information Technology

The _________________________ Tool erases the background while maintaining the edges of an object in the foreground, based on a set color that you choose for the background.

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

Computer Science & Information Technology

Which of the following statements is false?

a. IntStream methods range and rangeClosed each produce an ordered sequence of int values. b. IntStream methods range and rangeClosed take two int arguments representing the range of values. c. Method range produces a sequence of values from its first argument up to its second argument. d. Method rangeClosed produces a sequence of values including both of its arguments.

Computer Science & Information Technology

Solve the equations for the variable indicated, in terms of the remaining variable(s).

p+3p— 1 = 2

Computer Science & Information Technology