C++ Programming
EXCEPTIONS AND EFFICIENCY MCQs
Total Questions : 10
If an error occurs in program, then only exception object is created otherwise, It will not be
created. So it's expensive to use in the program.
The purpose of a constructor is to establish the class invariant. To do that, it often needs to
acquire system resources or in general perform an operation that may fail.
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
As we missed the data type in the catch block, It will arise an error.
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
int num = 3;
7.
string str_bad = "wrong number used";
8.
try
9.
{
10.
if ( num == 1 )
11.
{
12.
throw 5;
13.
}
14.
if ( num == 2 )
15.
{
16.
throw 1.1f;
17.
}
18.
if ( num != 1 || num != 2 )
19.
{
20.
throw str_bad;
21.
}
22.
}
23.
catch (int a)
24.
{
25.
cout
As we are giving 3 to num, It is arising an exception named
"wrong number used".
Output:
$ g++ expef.cpp
$ a.out
wrong number used
As we are throwing the function and catching it with a correct data type, So this program will execute.
Output:
$ g++ expef.cpp
$ a.out
Executed
As the catch is created with a wrong type, So it will
arise a runtime error.
Output:
$ g++ expef.cpp
$ a.out
Testing multiple catches
terminate called after throwing an instance of /int'
:Aborted
It will be used to free all the resources that are used by block of code during execution.
The value will be allocated, if there is enough memory in the system.
Output:
$ g++ expef.cpp
$ a.out
Memory allocated
compilers may try to move the catch-code far away from the try-code, which reduces the
amount of code to keep in cache normally, thus enhancing performance.
None.
Recent Questions
Q. Which Of The Following Methods Can Be Used For Manufacturing....
Q. Bromine Is A
Q. The Branch Current Method Is Based On Kirchhoff's Voltage La....
Q. Which Is The Shortcut Key To Jump To The First Slide Of The ....
Q. The Earliest Known Epigraphic Evidence Of Bhagvatism Is
Q. the Average Of First 10 Odd Numbers Is?
Q. Who Was The Architect Who Designed "Taj Mahal" ?
Q. Antonym Of Supernal ?
Q. The Arranging Of Data In A Logical Sequence Is Called
Q. Gopal Krishna Gokhale
Q. After You Wet Your Hands You Should Apply ______ And _____ F....
Q. The Practical Limit Of Moisture Content Achieved In Air Dryi....
Q. The Sieder-Tate Correlation For Heat Transfer In Turbulent F....
Q. Which Of The Following Is Not A Measure Of Product Deficienc....
Q. After Choosing A Predefined Template, Which Option Has To Be....
Q. Who Has Won The Best Actor Award At The 67th National Awards....
Q. The Rails Get Out Of Their Original Positions Due To Insuffi....
Q. The Unit Of Pressure Most Commonly Found On A Surface Weathe....
Q. The Charging Time Constant Of A Circuit Consisting Of An Ind....
Q. Which Of Following Is First Sign Of Colorectal Cancer?