Exercise

1.What is the output of this program?
Note:Includes all required header files

using namespace std;
int main()
{
try
{
throw 'b';
}
catch (int param)
{
cout << "Int Exception";
}
catch (...)
{
cout << "Default Exception";
}
cout << "After Exception";
return 0;
}

A. Default Exception
    After Exception
B. Int Exception     After Exception
C. Int Exception
D. Default Exception

View Answer


2.What is the output of this program?
Note:Includes all required header files

using namespace std;
int main()
{
try
{
throw 10;
}
catch (...)
{
cout << "Default Exceptionn";
}
catch (int param)
{
cout << "Int Exceptionn";
}
return 0;
}

A. Default Exception
B. Int Exception
C. Compiler Error
D. None of the above

View Answer


3.What is the output of this program?
Note:Includes all required header files

using namespace std;
int main()
{
int P = -1;
try {
cout << "Inside try n";
if (P < 0)
{
throw P;
cout << "After throw n";
}
}
catch (int P ) {
cout << "Exception Caught n";
}
cout << "After catch n";
return 0;
}

A. Inside try
    Exception Caught
    After throw
    After catch
B. Inside try
    Exception Caught
    After catch
C. Inside try
    Exception Caught
D. Inside try
    After throw
    After catch

View Answer


4.What is the output of this program?
Note:Includes all required header files

using namespace std;
class Base {};
class Derived: public Base {};
int main()
{
Derived new;
try {
throw new;
}
catch(Base new) {
cout<<"Base Exception";
}
catch(Derived new) {
cout<<"Derived Exception";
}
return 0;
}

A. Derived Exception
B. Base Exception
C. Compiler Error
D. None of the above

View Answer


5.Which of the following is true about the following program
Note:Includes all required header files

using namespace std;
int main ()
{
try
{
throw 10;
}
catch (int new)
{
cout << "An exception occurred " << new << endl;
}
return 0;
}

A. 10
B. An exception
C. Error
D. An exception occurred 20

View Answer


6.What will be the output of this program?
Note:Includes all required header files

using namespace std;
class myexception: public exception
{
virtual const char* what() const throw()
{
return "My exception";
}
} ex;
int main ()
{
try
{
throw ex;
}
catch (exception& new)
{
cout << new.what() << endl;
}
return 0;
}

A.Exception
B. Error
C. My exception
D. runtime error

View Answer


7.What will be the output of this program?
Note:Includes all required header files

using namespace std;
int main ()
{
try
{
int* myarray = new int[1000];
cout << "allocated";
}
catch (exception& new)
{
cout << "Standard exception: " << new.what() << endl;
}
return 0;
}

A. Allocated
B. Standard exception
C. Depends on the memory
D. Error

View Answer


8. What will be the output of the following program?
Note:Includes all required header files

using namespace std;
int main( )
{
try
{
string strg1("Test");
string strg2("ing");
strg1.append(strg2, 4, 2);
cout << strg1 << endl;
}
catch (exception &new)
{
cout << "Caught: " << new.what() << endl;
cout << "Type: " << typeid(new).name() << endl;
};
return 0;
}

A. out of range
B. bad type_id
C. bad allocation
D. none of the mentioned

View Answer



Discussion

* You must be logged in to add comment.