MCQ On Exception Handling in C++: Multiple Choice Questions and Answers on C++ Exception Handling

MCQ on exception handling in C++ with answers and explanations for placement tests and job interviews. This C++ MCQ on exception handling is useful for the campus placement for all freshers including Engineering Students, MCA students, Computer and IT Engineers, etc.

Our C++ exception handling quiz (C++ exception handling multiple Choice Questions ) focuses on all areas of C++ exception handling and its concept. We will regularly update the Quiz on the C++ exception handling and most interesting thing is that questions come in a random sequence. So every time you will feel new questions.

You may have come across several C++ courses during your search for learning the C++ language. Our team of experts has carefully analyzed some C++ courses for you. You can check the courses, Trial of some courses is free.

 

Guideline of MCQ on Exception Handling in C++:

This MCQ on exception handling in C++ is intended for checking your knowledge of C++ exception handling. It takes 20 minutes to pass the C++ quiz on exception handling. If you don’t finish the C++ exception handling quiz within the mentioned time, all the unanswered questions will count as wrong. Every unanswered question will count as wrong. Quiz on exception handling in C++ has randomization features that give you a new question set at every attempt.

In this MCQ on exception handling in C++, we have also implemented a feature that not allowed the user to see the next question or finish the quiz without attempting the current C++ exception handling quiz.

0 votes, 0 avg

You have 20 minutes to take the MCQs on Exception Handling in C++

Your time has been Over.


C++ Exception Handling MCQ

C++ MCQ

MCQ On C++ Exception Handling

C++ Exception Handling MCQ: Multiple Choice Questions and Answers on C++ Exception Handling

1 / 12

What should be put in a try block?

1. Statements that might cause exceptions
2. Statements that should be skipped in case of an exception

2 / 12

Output of following program

#include<iostream>
using namespace std;
 
class Base {};
class Derived: public Base {};
int main()
{
   Derived d;
   try {
       throw d;
   }
   catch(Base b) {
        cout<<"Caught Base Exception";
   }
   catch(Derived d) {
        cout<<"Caught Derived Exception";
   }
   return 0;
}

 

3 / 12

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

 

1.

Inside try
Exception Caught
After throw 
After catch

2. 

Inside try
Exception Caught
After catch

3. 

Inside try
Exception Caught

4. 

Inside try
After throw
After catch

4 / 12

#include <iostream>
using namespace std;
 
class Test {
  static int count;
  int id;
public:
  Test() {
    count++;
    id = count;
    cout << "Constructing object number " << id << endl;
    if(id == 4)
       throw 4;
  }
  ~Test() { cout << "Destructing object number " << id << endl; }
};
 
int Test::count = 0;
 
int main() {
  try {
    Test array[5];
  } catch(int i) {
    cout << "Caught " << i << endl;
  }
}

 

1. 

Constructing object number 1
Constructing object number 2
Constructing object number 3
Constructing object number 4
Destructing object number 1
Destructing object number 2
Destructing object number 3
Destructing object number 4
Caught 4

2.

Constructing object number 1
Constructing object number 2
Constructing object number 3
Constructing object number 4
Destructing object number 3
Destructing object number 2
Destructing object number 1
Caught 4

3. 

Constructing object number 1
Constructing object number 2
Constructing object number 3
Constructing object number 4
Destructing object number 4
Destructing object number 3
Destructing object number 2
Destructing object number 1
Caught 4

4. 

Constructing object number 1
Constructing object number 2
Constructing object number 3
Constructing object number 4
Destructing object number 1
Destructing object number 2
Destructing object number 3
Caught 4

5 / 12

#include <iostream>
using namespace std;
 
int main()
{
    try
    {
        try
        {
            throw 20;
        }
        catch (int n)
        {
            cout << "Inner Catchn";
            throw;
        }
    }
    catch (int x)
    {
        cout << "Outer Catchn";
    }
    return 0;
}

 

1.

Outer Catch

2.

Inner Catch

3.

Inner Catch
Outer Catch

4.

Compiler Error

 

6 / 12

What happens in C++ when an exception is thrown and not caught anywhere like following program.

#include <iostream>
using namespace std;
 
int fun() throw (int)
{
    throw 10;
}
 
int main() {
 
  fun();
 
  return 0;
}

 

7 / 12

Which of the following is true about exception handling in C++? 1) There is a standard exception class like Exception class in Java. 2) All exceptions are unchecked in C++, i.e., compiler doesn't check if the exceptions are caught or not. 3) In C++, a function can specify the list of exceptions that it can throw using comma separated list like following.

void fun(int a, char b) throw (Exception1, Exception2, ..) 

 

8 / 12

What happens when a function throws an error but doesn't specify it in the list of exceptions it can throw. For example, what is the output of following program?

#include <iostream>
using namespace std;
 
// Ideally it should have been "int fun() (int)"
int fun()
{
    throw 10;
}
 
int main()
{
    try
    {
        fun();
    }
    catch (int )
    {
        cout << "Caught";
    }
    return 0;
}

 

9 / 12

#include <iostream>
using namespace std;
 
class Test {
public:
   Test() { cout << "Constructing an object of Test " << endl; }
  ~Test() { cout << "Destructing an object of Test "  << endl; }
};
 
int main() {
  try {
    Test t1;
    throw 10;
  } catch(int i) {
    cout << "Caught " << i << endl;
  }
}

 

1. 

Caught 10

2.

Constructing an object of Test 
Caught 10

3. 

Constructing an object of Test 
Destructing an object of Test 
Caught 10

4. 

Compiler Errror

10 / 12

What is the advantage of exception handling ?

  1. Remove error-handling code from the software's main line of code.
  2. A method writer can chose to handle certain exceptions and delegate others to the caller.
  3. An exception that occurs in a function can be handled anywhere in the function call stack

11 / 12

#include <iostream>
using namespace std;
 
int main()
{
    try
    {
       throw 'a';
    }
    catch (int param)
    {
        cout << "int exceptionn";
    }
    catch (...)
    {
        cout << "default exceptionn";
    }
    cout << "After Exception";
    return 0;
}

 

1. 

default exception
After Exception

2. 

int exception
After Exception

3. 

int exception

4. 

default exception

12 / 12

#include <iostream>
using namespace std;
 
int main()
{
    try
    {
       throw 10;
    }
    catch (...)
    {
        cout << "default exceptionn";
    }
    catch (int param)
    {
        cout << "int exceptionn";
    }
 
    return 0;
}

 

Your score is

The average score is 0%

0%

Recommended Articles for you: