LakshyaEducation.in

VEDIC MATHS Video Series
  • Home
  • Video Series
    • Vedic Maths Videos
    • Quantitative Aptitude Videos
    • Class 8 Maths Videos
    • Class 9 Maths Videos
    • Class 10 Maths Videos
  • Quiz & Solutions
  • Blog
  • Store
  • Login
  • Contact Us
  • Home
  • Topic
  • C++ Programming
  • Error Handling

C++ Programming

ERROR HANDLING MCQs

Total Questions : 10

Question 1.

Which exception is thrown by dynamic_cast?


  1.    bad_cast
  2.    bad_typeid
  3.    bad_exception
  4.    bad_alloc
 Discuss Question
Answer is Option A. -> bad_cast

bad_cast exception is thrown by dynamic_cast.

Question 2.

How do define the user-defined exceptions?


  1.    inheriting and overriding exception class functionality.
  2.    overriding class functioality.
  3.    inheriting class functionality
  4.    none of the mentioned
 Discuss Question
Answer is Option A. -> inheriting and overriding exception class functionality.

None.

Question 3.


What is the output of this program?



1.
#include
2.
#include
3.
using namespace std;
4.
struct MyException : public exception
5.
{
6.
const char * what () const throw ()
7.
{
8.
return "C++ Exception";
9.
}
10.
};
11.
int main()
12.
{
13.
try
14.
{
15.
throw MyException();
16.
}
17.
catch(MyException& e)
18.
{
19.
cout
  1.    C++ Exception
  2.    Exception caught
  3.    Exception caught C++ Exception
  4.    error
 Discuss Question
Answer is Option C. -> Exception caught C++ Exception

We are defining the user-defined exception in this program.
Output:
$ g++ excep4.cpp
$ a.out
C++ Exception
Exception caught

Question 4.


What is the output of this program?



1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
try
7.
{
8.
int* myarray = new int[1000];
9.
cout
  1.    allocated
  2.    Standard exception
  3.    Depends on the memory
  4.    error
 Discuss Question
Answer is Option C. -> Depends on the memory

In this program, We are allocating the memory for array. If it is allocated means, no exception 

will arise and if there is no size in memory means, Exception will arise.
Output:
$ g++ excep3.cpp
$ a.out
allocated

Question 5.


What is the output of this program?



1.
#include
2.
#include
3.
using namespace std;
4.
class myexception: public exception
5.
{
6.
virtual const char* what() const throw()
7.
{
8.
return "My exception";
9.
}
10.
} myex;
11.
int main ()
12.
{
13.
try
14.
{
15.
throw myex;
16.
}
17.
catch (exception& e)
18.
{
19.
cout
  1.    exception
  2.    error
  3.    My exception
  4.    runtime error
 Discuss Question
Answer is Option C. -> My exception

This is a standard exception handler used in the class.
Output:
$ g++ excep2.cpp
$ a.out
My exception

Question 6.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
int main ()
4.
{
5.
try
6.
{
7.
throw 20;
8.
}
9.
catch (int e)
10.
{
11.
cout
  1.    20
  2.    An exception occurred
  3.    error
  4.    An exception occurred 20
 Discuss Question
Answer is Option D. -> An exception occurred 20

We are handling the exception by throwing that number. So the output is printed with the given number.
Output:
$ g++ excep1.cpp
$ a.out
An exception occurred 20

Question 7.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
double division(int a, int b)
4.
{
5.
if (b == 0)
6.
{
7.
throw "Division by zero condition!";
8.
}
9.
return (a / b);
10.
}
11.
int main ()
12.
{
13.
int x = 50;
14.
int y = 0;
15.
double z = 0;
16.
try
17.
{
18.
z = division(x, y);
19.
cout
  1.    50
  2.    0
  3.    Division by zero condition!
  4.    error
 Discuss Question
Answer is Option C. -> Division by zero condition!

It's a mathematical certainty, We can't divide by zero, So we're arising a exception.
Output:
$ g++ excep.cpp
$ a.out
Division by zero condition!

Question 8.

Which is used to throw a exception?


  1.    throw
  2.    try
  3.    catch
  4.    none of the mentioned
 Discuss Question
Answer is Option A. -> throw

None.

Question 9.

What is the use of the 'finally' keyword?


  1.    It used to execute at the starting of the program
  2.    It will be executed at the end of the program even if the exception arised.
  3.    Both a & b
  4.    none of the mentioned
 Discuss Question
Answer is Option B. -> It will be executed at the end of the program even if the exception arised.

finally keyword will be executed at the end of all the exception.

Question 10.

Which keyword is used to handle the expection?


  1.    try
  2.    throw
  3.    catch
  4.    none of the mentioned
 Discuss Question
Answer is Option C. -> catch

When we found a exception in the program, We need to throw that and we handle that by using 

  • Share on Facebook!
  • Share on Pinterest!

Sub Topics

  • Abstract Classes
  • Access Control
  • Argument Passing
  • Arrays
  • Booleans
  • C++ Concepts
  • Catching Exceptions
  • Character Types
  • Class Hierarchies And Abstract Classes
  • Class Hierarchies Introduction
  • Classes
  • Comments And Indentation
  • Complex Number Type
  • Constants
  • Constructors And Destructors
  • Container Design
  • Conversion Operators
  • Declaration
  • Default Arguments
  • Dereferencing
  • Derivation And Templates
  • Derived Classes
  • Design Of Class Hierarchies
  • Enumerations
  • Error Handling
  • Error Handling Alternatives
  • Essential Operators
  • Exception Specifications
  • Exceptions
  • Exceptions And Efficiency
  • Exceptions That Are Not Errors
  • Floating Point Types
  • Free Store
  • Friends
  • Function Call
  • Function Declarations
  • Function Templates
  • Functions
  • Grouping Of Exceptions
  • Header Files Usage
  • Increment And Decrement
  • Integer Types
  • Large Objects
  • Linkage
  • Macros
  • Modularization And Interfaces
  • Multiple Inheritance
  • Namespaces
  • Objects
  • Objects And Classes
  • Oops Concepts
  • Operator Functions
  • Operators
  • Overloaded Function Names
  • Pointer To Function
  • Pointer To Void
  • Pointers
  • Pointers Into Arrays
  • Pointers To Members
  • References
  • Resource Management
  • Run Time Type Information
  • Sequence Adapters
  • Sequences
  • Simple String Template
  • Sizes
  • Specialization
  • Standard Exceptions
  • Standard Library Design
  • Statements
  • String Class
  • Structures
  • Subscripting
  • Template Arguments To Specify Policy Usage
  • Types
  • Uncaught Exceptions
  • Unspecified Number Of Arguments
  • User Defined Types
  • Value Return
  • Vector
  • Void

Recent Posts

  • Quantitative Aptitude Faqs
  • Ssc Exam Guide Book
  • Sail E0 Results 2022
  • Is Ssc Difficult Than Upsc?
  • Sail E0 Exam Results Cancelled - Exam Will Be Rescheduled
  • Best Ssc Exam For Girls
  • Vedic Maths Faq

Recent Questions

Q.   In Submerged Arc Welding, An Arc Is Produced Between A

Q.   The Dinesh Goswami Committee Recommended

Q.   Which Command Is Used To Remove A Directory?

Q.   Least Accurate Instrument For Measuring Volume Is

Q.   Sometimes The Overhead Of Keeping Track Of A Hole Might Be :....

Q.   The Rectifier Instrument Is Not Free From

Q.   The Two Links OA And OB Are Connected By A Pin Joint At O. I....

Q.   Which Of The Following Has Lower Sp. Gravity V

Q.   Which Of The Following Best Describes The Aim Of Sustainable....

Q.   LOST

Q.   Lance Armstrong, A Sportsperson Of International Repute, Bel....

Q.   In A 3 Phase Full Converter The Average Load Current Is 150 ....

Q.   Intracellular Structures Formed During Many Viral Infections....

Q.   Look At This Series: 1,000, 200, 40, . . . What Number Shoul....

Q.   Find Out Whether There Is Any Grammatical Error In Below Sen....

Q.   The Oath Of Office Is Administered To The Members Of State C....

Q.   Higher CO₂ Concentration Stimulates:

Q.   The Latest Release Of The OBIEE Was In

Q.   An Interpreter Is

Q.   If Sodium (Na) Is Burned In Limited Supply Of Oxygen (O₂),....

Topics

Computer Aptitude
SAIL Junior Officer (E-0)
10th Grade
11th Grade
12th Grade
4th Grade
5th Grade
6th Grade
7th Grade
8th Grade
9th Grade
NCERT
Cat
Commerce
Computer Science
Engineering
English
General Knowledge
Ias
Management
Quantitative Aptitude
Reasoning Aptitude
General Studies (Finance And Economics)
Vedic Maths
Analytical Instrumentation
Biochemistry
Bioinformatics
Biology
Biotechnology
Bitsat
Business Statistics
C Programming
C++ Programming
Cell Biology
Chemistry
Cost Accounting
Drug And Pharmaceutical Biotechnology
Electrical Measurement And Instrumentation
Environment Management
Environmental Biotechnology
Enzyme Technology
Financial Management And Financial Markets
Gate
General Science
Geography
Heat Transfer
History And National Movements
Human Anatomy And Physiology
Human And Cultural Diversity
Human Resource Management
Indian Economy
Indian Geography
Indian History
Indian Polity
Instrumentation Transducers
International Relations
Life Sciences
Marketing And Marketing Management
Mass Transfer
Mechanics Of Materials
Microbiology
Neet
Professional Communication
Renewable Energy
Sociology
Surveying
Total Quality Management
Uidai Aadhaar Supervisor Certification
Virology
LakshyaEducation.in
Lakshya Education
Bhilai,Chattisgarh,India
Email: admin@lakshyaeducation.in Phone: 07893519977 (WhatsApp)

Quick Links

  • Vedic Maths
  • Quantitative Aptitude
  • Class – IX Maths
  • Class – X Maths
  • Blog

Our Services

  • About us
  • Privacy
  • TOS
  • Refund / Cancellation
  • Contact
  • Affiliate Program
  • Copyright © 2022 All Right Reserved | Lakshya Education     ( )
    Login / Register

    Your Account will be created automatically when you click the below Google or Facebook Login Button.
    •   Login With Facebook
    •  Login With Google
     Login With Email/Password