C++ Programming
STANDARD EXCEPTIONS MCQs
Total Questions : 10
None.
Because the dynamic allocations can change at any time, So it is best to include in try block.
As there is no object in the class, It is arising an exception in the program.
Output:
$ g++ std4.cpp
$ a.out
The object is null
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
class shape
5.
{
6.
public:
7.
virtual void myvirtualfunc() const {}
8.
};
9.
class mytriangle: public shape
10.
{
11.
public:
12.
virtual void myvirtualfunc() const
13.
{
14.
};
15.
};
16.
int main()
17.
{
18.
shape shape_instance;
19.
shape &ref_shape = shape_instance;
20.
try
21.
{
22.
mytriangle &ref_mytriangle = dynamic_cast(ref_shape);
23.
}
24.
catch (bad_cast)
25.
{
26.
cout
As we are not able to allocate the values by using dynamic cast,
So it is arising an exception.
Output:
$ g++ std3.cpp
$ a.out
Caught: bad_cast exception
As we are dividing the zero by three, it is returning 0.
Output:
$ g++ std2.cpp
$ a.out
0
Variable will be allocated depends on the available space in the memory, If there is no space
means, It will throw an exception.
Output:
$ g++ std1.cpp
$ a.out
Allocated
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.
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
class myexc: 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
This is a type of exception arising in the class. We can call this
also as a standard exception.
Output:
$ g++ std.cpp
$ a.out
My exception
As these are standard exceptions, they need to be defined in the standard block, So it is defined
under namespace std.
Answer:a
Explanation:None.
Recent Questions
Q. According To The Affordable Care Act, Children Can Be On The....
Q. A Truncated Polypeptide Is Synthesized Due To A Nonsense Mut....
Q. How Do The British Economists And Political Scientists React....
Q. Which Of The Following Is Not A Product Of Anaerobic Digesti....
Q. The Ratio For The Rate Of Washing To The Final Rate Of Filtr....
Q. To Turn On UJT, The Forward Bias On The Emitter Diode Should....
Q. Which Of The Following IR Radiation Is Used In Measuring Rel....
Q. The Hottest Part Of The Gas Flame Is Known As
Q. Ethyl Alcohol Cannot Be Produced
Q. Which Of The Following Can Be Correct Conclusion Drawn From ....
Q. ISS Is Less Sensitive Than Which Of The Following?
Q. Which Of The Following Is The Most Effective Inhibitor Of Gr....
Q. A Metallic Alloy In Which One Of The Constituent Metal Is __....
Q. Defense Department Analysts Worry That The Ability Of The Un....
Q. S1: If You Want To Do Well In Your Examinations You Need To ....
Q. Which One Of The Following Is Also Known As Solution ?
Q. (0.1667)(0.8333)(0.3333) Is Approximately Equal To: ....
Q. IR Is The Study Of
Q. if The Radius Of A Sphere Is Increased By 2 Cm, Then Its S....
Q. Statement I: When Water Is Heated, We See bubbles In It....