Question: throw ( rand ( ) % 2 ? DerivedException ( DerivedException ) : DerivedException 2 ( DerivedException 2 ) ) ; } catch (
throw rand DerivedException "DerivedException" :
DerivedException "DerivedException;
catch BaseException &b
bprint;
return ;
C Write a program which shows that all destructors for objects constructed in a block are
called before an exception is thrown from that block.using std::cout;
using std::cerr;
class Object
public:
Object int val : value val
cout "Object value constructor
;
sim Object
cout "Object value destructor
;
private:
int value;
;
class Error
public:
Error char s : string s
private:
char string;
;
int main
try
Object a b c;
cout
;
throw Error "This is a test exception" ;
catch Error &e
eprint;
return ;
A Suppose a program throws an exception and the appropriate exception handler begins
executing. Now suppose that the exception handler itself throws the same exception. Does this
create an infinite recursion? Write a program in to check your observation.using std::cout;
class TestException
public:
TestException char mPtr : message mPtr
private:
char message;
;
int main
try
throw TestException "This is a test" ;
catch TestException &t
tprint;
throw TestException "This is another test" ;
return ;
B Use inheritance to create a base exception class and various derived exception classes. Then
show that a catch handler specifying the base class can catch derivedclass exceptions.using std::cout;
#include
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
