(Order of Exception Handlers) Write a program illustrating that the order of exception han- dlers is important. The first matching handler is the one that executes. Attempt to compile and run your program two different ways to show that two different handlers execute with two different ef- fects.
What will be an ideal response?
```
#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()
{
try // throw TestException
{
// throw an exception of the derived class
throw TestException( "This is a TestException" );
} // end try
catch ( runtime_error &exception ) // catch runtime_error exception
{
cout << "runtime_error was caught\n" << exception.what() << endl;
} // end catch
catch ( TestException &exception ) // catch TestException
{
cout << "TestException was caught\n" << exception.what() << endl;
} // end catch
return 0;
} // end main
```
runtime_error was caught
This is a TestException
You might also like to view...
Real-time processing means that transactions are updated when they occur
Indicate whether the statement is true or false
A(n) ________ in a database can be a data source for a PivotChart
Fill in the blank(s) with the appropriate word(s).