Skip to content
main-logo
  • +91 637-050-2482
  • santuitreturns@gmail.com
Menu
Menu
  • Home
  • Income Tax
    • Income From Salary
    • Profit or gain from Business/Profession.
    • Capital Gain
    • Income From Other Sources
    • 80C to 80U
    • TDS & TCS
    • ITR FORMS
  • International Taxation
    • Transfer Pricing
    • Non-Resident Taxation
    • Foreign Tax Credit (FTC)
    • Model Tax Convention
    • Base Erosion and Profit Shifting (BEPS)
  • GST
  • Accounting
  • MCQs
    • NEET
    • NEET QUIZ TEST
    • NEET PG MCQ’s
    • NEET PG QUIZ TEST
    • Civil Engineering
    • Mechanical Engineering MCQs
    • CHSL EXAM
      • Logical Reasoning
  • Others
    • Job Tips
  • CA Courses
    • CA Inter/IPCC

10+ TOP C++ MCQs on Standard Exceptions

Posted on September 27, 2023

1. Which header file is used to declare the standard exception?

A. #include<exception>
B. #include<except>
C. #include<error>
D. #include<exce>

View Answer

Answer: A

Explanation: 

 #include<exception> is used to declare the standard exception.

2. Where are standard exception classes grouped?

A. namespace std
B. error
C. catch
D. final

View Answer

Answer: A

Explanation:

 As these are standard exceptions, they need to be defined in the standard block, So it is defined under namespace std.

3. How many types of standard exception are there in c++?

A. 9
B. 5
C. 6
D. 7

View Answer

Answer: A

Explanation:

: There are nine standard exceptions in c++. They are bad_alloc, bad_cast, bad_exception, bad_function_call, bad_typeid, bad_weak_ptr, ios_base::failure, logic_error and runtime_error.

4. What will be the output of the following C++ code?
    #include <iostream>
    #include <exception>
    using namespace std;
    class myexc: 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;
    }

A. My
B. My exception
C. No exception
D. exception

View Answer

Answer: A

Explanation:

: We are checking the type id of char and float as they are not equal, We are printing c.

5. What will be the output of the following C++ code?
    #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;
    }

A. Allocated
B. Standard exception:
C. bad_alloc
D. Depends on memory

View Answer

Answer: D

Explanation:

: Variable will be allocated depends on the available space in the memory, If there is no space means, It will throw an exception.

6. What will be the output of the following C++ code?
    #include<iostream> 
    using namespace std;
    int main()
    {
        char* ptr;
        unsigned long int a = (size_t(0) / 3);
        cout << a << endl;
        try
        {
            ptr = new char[size_t(0) / 3];
            delete[ ] ptr;
        }
        catch(bad_alloc &thebadallocation)
        {
            cout << thebadallocation.what() << endl;
        };
        return 0;
    }

A. 0
B. 2
C. bad_alloc
D. depends on compiler

View Answer

Answer: A

Explanation:

: As we are dividing the zero by three, it is returning 0.

7. What will be the output of the following C++ code?
    #include <typeinfo> 
    #include <iostream>
    using namespace std;
    class shape
    {
        public:
        virtual void myvirtualfunc() const {}
    };
    class mytriangle: public shape
    {
        public:
        virtual void myvirtualfunc() const
        {   
        };
    };
    int main()
    {
        shape shape_instance;
        shape &ref_shape = shape_instance;
        try 
        {
            mytriangle &ref_mytriangle = dynamic_cast(ref_shape);
        }
        catch (bad_cast) 
        {
            cout << "Caught: bad_cast exception\n";
        }
        return 0;
    }

A. Caught standard exception
B. No exception arises
C. Caught: bad_cast exception
D. Caught: cast

View Answer

Answer: C

Explanation:

: As we are not able to allocate the values by using dynamic cast, So it is arising an exception.

8. What will be the output of the following C++ code?
    #include<typeinfo>
    #include <iostream>
    using namespace std;
    class Test
    {
        public:
        Test();
        virtual ~Test();
    };
    int main()
    {
        Test *ptrvar = NULL;
        try 
        {
            cout << typeid(*ptrvar).name() << endl;
        }
        catch (bad_typeiD. 
        {
            cout << "The object is null" << endl;
        }
        return 0;
    }

A. No exception arises
B. The object is null
C. Error
D. The object is

View Answer

Answer: B

Explanation:

: As there is no object in the class, It is arising an exception in the program.

9. Which of the following is best to include under try block?

A. static values
B. const values
C. dynamic allocations
D. default values

View Answer

Answer: C

Explanation:

: Because the dynamic allocations can change at any time, So it is best to include in try block.

10. What are the predefined exceptions in c++?

A. Memory allocation errors
B. I/O errors
C. Both Memory allocation errors & I/O errors
D. static errors

View Answer

Answer: C

Explanation:

: Both Memory allocation errors & I/O errors are the predefined exceptions in c++.

    You May Also Like...

  • 10+ TOP MCQs on C++ Concepts-3
  • 10+ TOP C++ MCQs on Static Constant Keyword
  • 10+ TOP C++ MCQs on Pointers
  • 10+ TOP C++ MCQs on Arrays
  • 10+ TOP C++ MCQs on Linkage
  • 10+ TOP C++ MCQs on Friends
  • 10+ TOP C++ MCQs on Friend Function
  • 10+ TOP C++ MCQs on Constructors and Destructors – 1

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Quick Links

  • Home
  • About Us
  • Privacy Policy
  • Terms of Use
  • Disclaimer
  • Contact Us

Categories

  • Income Tax
  • International Taxation
  • GST
  • MCQs
  • Others
  • CA Courses

Latest Posts

  • Five changes in ITR forms of FY 2024-25 (AY 2025-26)
  • Form 10-IEA: Option to Choose Old Tax Regime
  • What is Section 54EC of the Income Tax Act?
  • What is Section 54F of the Income Tax Act?
©2025 Online Solves. All rights Reserved | Developed by AlgoPage IT Solutions Pvt. Ltd.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT