GoConqr has a new look! Let us know what you think.

Quiz

C++ Exception Handling

PathaPadha Support 12 questions

Take the quiz

This quiz has a time limit, so it opens in the usual player.

Questions in this quiz (12)

  1. 1#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. AInside try
      Exception Caught
      After throw
      After catch
    2. BInside try
      Exception Caught
      After catch
    3. CInside try
      Exception Caught
    4. DInside try
      After throw
      After catch
  2. 2What 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.
    1. Aonly 1
    2. B1, 2, 3
    3. C1,3
    4. D1,2
  3. 3What should be put in a try block?

    1. Statements that might cause exceptions
    2. Statements that should be skipped in case of an exception
    1. AOnly 1
    2. BOnly 2
    3. CBoth 1 and 2
  4. 4Output 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;
    }
    1. ACaught Derived Exception
    2. BCaught Base Exception
    3. CCompiler Error
  5. 5#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. Adefault exception
      After Exception
    2. Bint exception
      After Exception
    3. Cint exception
    4. Ddefault exception
  6. 6#include <iostream>
    using namespace std;

    int main()
    {
    try
    {
    throw 10;
    }
    catch (...)
    {
    cout << "default exceptionn";
    }
    catch (int param)
    {
    cout << "int exceptionn";
    }

    return 0;
    }
    1. Adefault exception
    2. Bint exception
    3. CCompiler Error
  7. 7#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. AOuter Catch
    2. BInner Catch
    3. CInner Catch
      Outer Catch
    4. DCompiler Error
  8. 8#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;
    }
    }#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. ACaught 10
    2. BConstructing an object of Test
      Caught 10
    3. CConstructing an object of Test
      Destructing an object of Test
      Caught 10
    4. DCompiler Errror
  9. 9#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. AConstructing 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. BConstructing 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. CConstructing 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. DConstructing 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
  10. 10Which 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, ..)
    1. A1,3
    2. B1,2,3
    3. C1,2
    4. D2,3

Information

Description
C++ Quiz on C++ Exception Handling, created by PathaPadha Support on 04/11/2020.
Language
English
Views
220
Tags
c++
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?