1. Which keyword is used to handle the expection?
a) try
b) throw
c) catch
d) none of the mentioned
2. Which is used to throw a exception?
a) throw
b) try
c) catch
d) none of the mentioned
3. What is the use of the ‘finally’ keyword?
a) It used to execute at the starting of the program
b) It will be executed at the end of the program even if the exception arised.
c) Both a & b
d) none of the mentioned
4. What is the output of this program?
a) 50
b) 0
c) Division by zero condition!
d) error
5. What is the output of this program?
a) 20
b) An exception occurred
c) error
d) An exception occurred 20
6. What is the output of this program?
a) exception
b) error
c) My exception
d) runtime error
7. What is the output of this program?
a) allocated
b) Standard exception
c) Depends on the memory
d) error
8. What is the output of this program?
a) C++ Exception
b) Exception caught
c) C++ Exception
Exception caught
d) error
9. How do define the user-defined exceptions?
a) inheriting and overriding exception class functionality.
b) overriding class functioality.
c) inheriting class functionality
d) none of the mentioned
10. Which exception is thrown by dynamic_cast?
a) bad_cast
b) bad_typeid
c) bad_exception
d) bad_alloc
a) try
b) throw
c) catch
d) none of the mentioned
Answer:c
2. Which is used to throw a exception?
a) throw
b) try
c) catch
d) none of the mentioned
Answer:a
3. What is the use of the ‘finally’ keyword?
a) It used to execute at the starting of the program
b) It will be executed at the end of the program even if the exception arised.
c) Both a & b
d) none of the mentioned
Answer:b
4. What is the output of this program?
#include <iostream>
using namespace std;
double division(int a, int b)
{
if (b == 0)
{
throw "Division by zero condition!";
}
return (a / b);
}
int main ()
{
int x = 50;
int y = 0;
double z = 0;
try
{
z = division(x, y);
cout << z << endl;
}
catch (const char* msg)
{
cerr << msg << endl;
}
return 0;
}
b) 0
c) Division by zero condition!
d) error
Answer:c
5. What is the output of this program?
#include <iostream>
using namespace std;
int main ()
{
try
{
throw 20;
}
catch (int e)
{
cout << "An exception occurred " << e << endl;
}
return 0;
}
b) An exception occurred
c) error
d) An exception occurred 20
Answer:d
6. What is the output of this program?
#include <iostream>
#include <exception>
using namespace std;
class myexception: public exception
{
virtual const char* what() const throw()
{
return "My exception";
}
} myex;
int main ()
{
try
{
throw myex;
}
catch (exception& e)
{
cout << e.what() << endl;
}
return 0;
}
b) error
c) My exception
d) runtime error
Answer:c
7. What is the output of this program?
#include <iostream>
#include <exception>
using namespace std;
int main ()
{
try
{
int* myarray = new int[1000];
cout << "allocated";
}
catch (exception& e)
{
cout << "Standard exception: " << e.what() << endl;
}
return 0;
}
b) Standard exception
c) Depends on the memory
d) error
Answer:c
8. What is the output of this program?
#include <iostream>
#include <exception>
using namespace std;
struct MyException : public exception
{
const char * what () const throw ()
{
return "C++ Exception";
}
};
int main()
{
try
{
throw MyException();
}
catch(MyException& e)
{
cout << "Exception caught" << std::endl;
cout << e.what() << std::endl;
}
catch(std::exception& e)
{
}
}
b) Exception caught
c) C++ Exception
Exception caught
d) error
Answer:c
9. How do define the user-defined exceptions?
a) inheriting and overriding exception class functionality.
b) overriding class functioality.
c) inheriting class functionality
d) none of the mentioned
Answer:a
10. Which exception is thrown by dynamic_cast?
a) bad_cast
b) bad_typeid
c) bad_exception
d) bad_alloc
Answer:a