1. To where does the program control transfers when exception is arised?
a) catch
b) handlers
c) throw
d) none of the mentioned
2. Which key word is used to check exception in the block of code?
a) catch
b) throw
c) try
d) none of the mentioned
3. What will happen when the exception is not caught in the program?
a) error
b) program will execute
c) block of that code will not execute
d) none of the mentioned
4. What is the output of this program?
a) 0
b) Error:Positive Number Required
c) compile time error
d) none of the mentioned
5. What is the output of this program?
a) compile time error
b) prints first 19 numbers
c) prints first 19 numbers and throws exception at 20
d) none of the mentioned
6. What is the output of this program?
a) 25
b) 20
c) Division by zero condition!
d) none of the mentioned
7. What is the output of this program?
a) 4 Bytes allocated successfully
b) 8 Bytes allocated successfully
c) Memory allocation failure
d) depends on the size of data type
8. What is the output of this program?
a) caught a double type
b) compile time error
c) abnormal program termination
d) none of the mentioned
9. What is the output of this program?
a) Allocated successfully
b) error allocating the requested memory
c) Depends on the memory of the computer
d) none of the mentioned
10. What will happen when the handler is not found for exception?
a) Calls the standard library function terminate()
b) raise an error
c) executes the remaining block
d) none of the mentioned
a) catch
b) handlers
c) throw
d) none of the mentioned
2. Which key word is used to check exception in the block of code?
a) catch
b) throw
c) try
d) none of the mentioned
3. What will happen when the exception is not caught in the program?
a) error
b) program will execute
c) block of that code will not execute
d) none of the mentioned
4. What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
int age = 0;
try {
if (age < 0) {
throw "Positive Number Required";
}
cout << age;
}
catch(const char *Message)
{
cout << "Error: " << Message;
}
return 0;
}
b) Error:Positive Number Required
c) compile time error
d) none of the mentioned
5. What is the output of this program?
#include <iostream>
using namespace std;
void PrintSequence(int StopNum)
{
int Num;
Num = 1;
while (true) {
if (Num >= StopNum)
throw Num;
cout << Num;
Num++;
}
}
int main(void)
{
try {
PrintSequence(20);
}
catch(int ExNum)
{
cout << "Caught an exception with value: " << ExNum;
}
return 0;
}
b) prints first 19 numbers
c) prints first 19 numbers and throws exception at 20
d) none of the mentioned
6. 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 = 2;
double z = 0;
try {
z = division(x, y);
cout << z;
}
catch(const char *msg) {
cerr << msg;
}
return 0;
}
b) 20
c) Division by zero condition!
d) none of the mentioned
7. What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
char* buff;
try {
buff = new char[1024];
if (buff == 0)
throw "Memory allocation failure!";
else
cout << sizeof(buff) << "Byte successfully allocated!"<<endl;
}
catch(char *strg) {
cout<<"Exception raised: "<<strg<<endl;
}
return 0;
}
b) 8 Bytes allocated successfully
c) Memory allocation failure
d) depends on the size of data type
8. What is the output of this program?
#include <iostream>
using namespace std;
void Funct();
int main()
{
try {
Funct();
}
catch(double) {
cerr << "caught a double type..." << endl;
}
return 0;
}
void Funct()
{
throw 3;
}
b) compile time error
c) abnormal program termination
d) none of the mentioned
9. What is the output of this program?
#include <iostream>
#include <exception>
using namespace std;
int main()
{
try {
int * array1 = new int[100000000];
int * array2 = new int[100000000];
int * array3 = new int[100000000];
int * array4 = new int[100000000];
cout << "Allocated successfully";
}
catch(bad_alloc&) {
cout << "Error allocating the requested memory." << endl;
}
return 0;
}
b) error allocating the requested memory
c) Depends on the memory of the computer
d) none of the mentioned
10. What will happen when the handler is not found for exception?
a) Calls the standard library function terminate()
b) raise an error
c) executes the remaining block
d) none of the mentioned