(Cathing All Exceptions) Write a program that demonstrates several exception types being caught with the catch(...) exception handler.
What will be an ideal response?
```
#include
#include
using namespace std;
// class TestException1 definition
class TestException1 : public runtime_error
{
public:
// constructor specifies error message
TestException1::TestException1()
: runtime_error( "TestException1" ) {}
}; // end class TestException1
```
```
#include
#include
using namespace std;
// class TestException2 definition
class TestException2 : public runtime_error
{
public:
// constructor specifies error message
TestException2::TestException2()
: runtime_error( "TestException2" ) {}
}; // end class TestException2
```
```
#include
#include
#include
#include "TestException1.h"
#include "TestException2.h"
using namespace std;
void generateException();
int main()
{
srand( time( 0 ) ); // using current time to randomize random number
// loop 5 times to generate various exceptions
for ( int i = 0; i < 5; i++ )
{
try // generate exception
{
generateException();
} // end try
catch( ... )
{
cerr << "The \"catch all\" exception handler was invoked\n";
} // end catch
} // end for
return 0;
} // end main
// throw exception randomly
void generateException()
{
int type = 1 + rand() % 3;
TestException1 exception1;
TestException2 exception2;
switch( type )
{
case 1: // throw int exception
cout << "\nThrowing exception of type int...\n";
throw( 10 );
case 2: // throw TestException1
cout << "\nThrowing exception of type TestException1...\n";
throw( exception1 );
case 3: // throw TestException2
cout << "\nThrowing exception of type TestException2...\n";
throw( exception2 );
} // end switch
} // end function generateException
```
Throwing exception of type TestException2...
The "catch all" exception handler was invoked
Throwing exception of type TestException1...
The "catch all" exception handler was invoked
Throwing exception of type TestException2...
The "catch all" exception handler was invoked
Throwing exception of type TestException1...
The "catch all" exception handler was invoked
Throwing exception of type int...
The "catch all" exception handler was invoked
You might also like to view...
List and describe five of the actions you can perform from the Actions pane of Hyper-V Manager.
What will be an ideal response?
When a wireless device running Windows attempts to connect to the WLAN it goes through a five-step process. List the steps in this process.
What will be an ideal response?
When you purchase from a store several times this would be an example of what kind of table relationship?
A) Many-to-many (many items purchased - many times) B) Many-to-one (many purchases - one customer) C) One-to-many (one customer - many purchases) D) One-to-one (one customer - one store)
Explain the process you created to ensure that when an employee clocks out, the time is recorded with the most recent time record instead of overriding a previous time
What will be an ideal response?