C++ Exception Handling Aptitude Questions and Answers

C++ Exception Handling Aptitude: This section contains C++ Exception Handling Aptitude Questions and Answers with explanations.
Submitted by Nidhi, on February 22, 2021

1) There are the following statements that are given below, which of them are correct about exception handling in C++?

  1. Exception handling is a new feature of C++, which is not available in C language.
  2. Exception handling is used to handle runtime errors.
  3. Exception handling is used to prevent the program crash.
  4. Exception handling is also used to handle the compile-time error.

Options:

  1. A and B
  2. A and C
  3. A, B, and C
  4. A, B, C, and D

2) Which of the following keywords are used for exception handling in C++?

  1. try
  2. catch
  3. through
  4. throughs

Options:

  1. A and B
  2. A and C
  3. A, B, and C
  4. A, B, C, and D

3) Which of the following are types of exceptions?

  1. Synchronous exception
  2. Asynchronous exception
  3. Interrupt
  4. Trap

Options:

  1. A and B
  2. A and C
  3. A, B, and C
  4. A, B, C, and D

4) Can we handle asynchronous exceptions using exception handling in C++?

  1. Yes
  2. No

5) Which of the following are the exception classes used in C++?

  1. exception
  2. exceptions
  3. runtime_error
  4. bad_cast

Options:

  1. A and B
  2. A and C
  3. A, B, and C
  4. A, C, and D

6) All exception classes are derived by the "exception" class in C++?

  1. Yes
  2. No

7) Which of the following exception class is used to detect exceptions that cannot be detected by reading source code in C++?

  1. runtime_error
  2. bad_cast
  3. bad_alloc
  4. logic_failure

8) Which of the following exception class is used to detect unexpected exceptions in C++?

  1. runtime_error
  2. bad_cast
  3. bad_exception
  4. logic_failure

9) Which of the following statement is correct about try block in C++?

  1. The try block contains statements that can generate exceptions.
  2. The try block is used to catch generated exceptions and handle them.
  3. Both of the above
  4. None of the above

10) Which of the following exceptions can be generated in the C++ program?

  1. Divide by zero
  2. File not found
  3. Index out of bound
  4. Buffer overflow

Options:

  1. A and B
  2. A and C
  3. A, B, and C
  4. A, B, C, and D

11) What is the correct output of the given code?

#include <iostream>
using namespace std;

int main()
{
    try {
        int A = 10;
        int B = 0;
        int C;

        if (B == 0)
            throw 2;

        C = A / B;
    }
    catch (int num) {
        cout << "Error code: " << num << endl;
    }
    return 0;
}

Options:

  1. Error code: 2
  2. Syntax error
  3. No output
  4. Garbage value

12) What is the correct output of the given code?

#include <iostream>
using namespace std;

int main()
{
    try {
        int A = 10;
        int B = 0;
        int C;

        C = A / B;
    }
    catch (exception e) {
        cout << "Exception generated" << endl;
    }
    return 0;
}

Options:

  1. Exception generated
  2. Syntax error
  3. No output
  4. Program crashed at runtime

13) What is the correct output of the given code?

#include <iostream>
using namespace std;

int main()
{
    try {
        int A = 10;
        int B = 0;
        int C;

        if (B == 0)
            throw "divide by zero";
        C = A / B;
    }
    catch (char* e) {
        cout << "Exception Received: " << e << endl;
    }
    return 0;
}

Options:

  1. Exception Received: divide by zero
  2. Syntax error
  3. No output
  4. Program crashed at runtime

14) What is the correct output of the given code?

#include <iostream>
using namespace std;

int main()
{
    try {
        int A = 10;
        int B = 0;
        int C;

        if (B == 0)
            throw "divide by zero";
        C = A / B;
    }
    catch (const char* e) {
        cout << "Exception Received: " << e << endl;
    }
    return 0;
}

Options:

  1. Exception Received: divide by zero
  2. Syntax error
  3. No output
  4. Program crashed at runtime

15) What is the correct output of the given code?

#include <iostream>
using namespace std;

int main()
{
    try {
        int A = 10;
        int B = 0;
        int C;

        if (B == 0)
            throw "Divide by zero";
        C = A / B;
    }
    catch (int num) {
        cout << "Error Code: " << num << endl;
    }
    catch (...) {
        cout << "Exception received" << endl;
    }
    return 0;
}

Options:

  1. Exception received
  2. Divide by zero
  3. Syntax error
  4. No output

16) What is the correct output of the given code?

#include <iostream>
using namespace std;

int main()
{
    try {
        int A = 10;
        int B = 0;
        int C;

        if (B == 0) {
            Exception E;
            throw E;
        }
        C = A / B;
    }
    catch (exception E) {
        cout << "Exception Received" << endl;
    }

    return 0;
}

Options:

  1. Exception Received
  2. Divide by zero
  3. Syntax error
  4. No Output

17) What is correct output of given code snippets?

#include <iostream>
using namespace std;

int main()
{
    try {
        int A = 10;
        int B = 0;
        int C;

        if (B == 0) {
            exception E;
            throw E;
        }
        C = A / B;
    }
    catch (exception E) {
        cout << "Exception Received" << endl;
    }

    return 0;
}

Options:

  1. Exception Received
  2. Divide by zero
  3. Syntax error
  4. No output

18) What is correct output of given code snippets?

#include <iostream>
using namespace std;

int main()
{
    try {
        int A = 10;
        int B = 0;
        int C;

        if (B == 0) {
            bad_exception E;
            throw E;
        }
        C = A / B;
    }
    catch (bad_exception E) {
        cout << "Exception Received" << endl;
    }

    return 0;
}

Options:

  1. Exception Received
  2. Divide by zero
  3. Syntax error
  4. No output

19) What is the correct output of the given code?

#include <iostream>
using namespace std;

int main()
{
    try {
        int A = 10;
        int B = 0;
        int C;

        if (B == 0) {
            bad_exception E;
            throw E;
        }
        C = A / B;
    }
    catch (exception E) {
        cout << "###Exception Received" << endl;
    }
    catch (bad_exception E) {
        cout << "@@@Exception Received" << endl;
    }

    return 0;
}

Options:

  1. ###Exception Received
  2. @@@Exception Received
  3. Syntax error
  4. No Output

20) What is the correct output of the given code?

#include <iostream>
using namespace std;

int main()
{
    try {
        int A = 10;
        int B = 0;
        int C;

        if (B == 0) {
            bad_exception E;
            throw E;
        }
        C = A / B;
    }
    catch (bad_exception E) {
        cout << "@@@Exception Received" << endl;
    }
    catch (exception E) {
        cout << "###Exception Received" << endl;
    }

    return 0;
}

Options:

  1. ###Exception Received
  2. @@@Exception Received
  3. Syntax error
  4. No output





Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.