Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started