Exception is thrown with the default constructor


Discuss the below:

Q: Suppose an exception, class myException, is defined as follows:

class myException
{
public:
myException()
{
message = "myException thrown!";
cout << "Immediate attention required!"
<< endl;
}
myException (string msg)
{
message = msg;
cout << "Attention required!" << endl;
}
string what()
{
return message;
}
private:
string message;
}

Suppose that in a user program, the catch block has the following form:

catch (myException mE)
{
cout << mE.what() << endl;
}

Q1. What output will be produced if the exception is thrown with the default constructor?

Q2. What output will be produced if the exception is thrown with the constructor with parameters with the following actual parameter?

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Exception is thrown with the default constructor
Reference No:- TGS01937460

Now Priced at $20 (50% Discount)

Recommended (98%)

Rated (4.3/5)