Unit 5 C++
Exception Handling
1) ___________ are run time anomalies or unusual conditions that a program may encounter
while executing.
a) Error b)Bug c)Exception d)Mistake
2) The errors that are caused by events beyond the control of the program (such as keyboard
interrupts) are called _____________.
a) Synchronous exceptions b) Asynchronous exceptions c) Both a and b d) None of the
above
3) Errors such as “out-of-range index “ and “over-flow” belong to ________ exceptions.
a) Synchronous exceptions b) Asynchronous exceptions c) Both a and b d) None of the
above
4) _________ is used to preface a block of statements which may generate exceptions.
a) try b) catch c) throw d)thrown
5) Exceptions are of __________ kinds.
a) 1 b) 2 c)3 d)4
6) C++ provides mechanism for handling __________ exceptions.
a) Synchronous exceptions b) Asynchronous exceptions c) Both a and b d) None of the
above
7) Taking corrective actions means ___________
a) Handle the exception b) Hit the exception c) Throw the exception d) Catch the
exception
7) C++ exception handling mechanism is basically built upon _____ keywords.
a) 1 b) 2 c) 3 d)4
8) When an exception is thrown, it will be caught by __________ statement associated with
try block.
a) catch b) try c)throw d) thrown
9) C++ exception handling mechanism is built upon following keywords
a) try b) throw c) catch d) All of the above
Unit 5 C++
10) ________ block detects and throws an exception.
a) try b)catch c) Both a and b d) None of the above
11) The point at which the throw is executed is called the ______________.
a) Throw point b) catch point c)Handle point d)Exception point
12) Which of the following is an exception in C++?
a) Divide by zero
b) Semicolon not written
c) Variable not declared
d) An expression is wrongly written
13) Which keyword is used to throw an exception?
a) try b) throw c) throws d) except
13) How Exception handling is implemented in the C++ program?
a) Using Exception keyword
b) Using try-catch block
c) Using Exception block
d) Using Error handling schedules
14) What is the correct syntax of the try-catch block?
a)
try
// programable codes.....
catch(Exceptions)
// Code for handling exceptions....
}
Unit 5 C++
b)
try()
// programable codes.....
catch(Exceptions)
// Code for handling exceptions....
c)
try
// programable codes.....
catch
// Code for handling exceptions....
d)
try()
{
Unit 5 C++
// programable codes.....
catch
// Code for handling exceptions....
15) What is an exception in C++ program?
a) A problem that arises during the execution of a program
b) A problem that arises during compilation
c) Also known as the syntax error
d) Also known as semantic error
16) Why do we need to handle exceptions?
a) To avoid unexpected behaviour of a program during run-time
b) To let compiler remove all exceptions by itself
c) To successfully compile the program
d) To get correct output
17) Which statement is used to catch all types of exceptions?
A. catch()
B. catch(Test t)
C. catch(...)
D. None of the above
18) What kind of exceptions are available in c++?
A. Handled
B. Unhandled
C. Static
D. Dynamic
19) Catch-all handlers uses which operators in c++?
A. String operators
B. Ternary operators
Unit 5 C++
C. Ellipses operators
D. Unary operators
20) Why do we need to handle exceptions?
a) To avoid unexpected behaviour of a program during run-time
b) To let compiler remove all exceptions by itself
c) To successfully compile the program
d) To get correct output
21) What is the difference between error and exception?
a) Both are the same
b) Errors can be handled at the run-time but the exceptions cannot
c) Exceptions can be handled at the run-time but the errors cannot
d) Both can be handled during run-time
22) What are the different types of exceptions?
a) 1
b) 2
c) 3
d) 4
23) What is Re-throwing an exception means in C++?
a) An exception that is thrown again as it is not handled by that catching block
b) An exception that is caught twice
c) An exception that is not handled in one caught hence thrown again
d) All of the mentioned
24) By default, what a program does when it detects an exception?
A. Continue running
B. Calls other functions of the program
C. Results in the termination of the program
D. Removes the exception and tells the programmer about an exception
25) The C++ code which causes abnormal termination/behaviour of a program should be written under
_________ block.
Unit 5 C++
A. try
B. catch
C. throw
D. finally
26) Uncaught exception leads to ______________
A. no effect on the program
B. termination of program
C. successful execution of programs
D. execution of other functions of the program starts
27) Generic catch handler is represented by ______________ .
A. catch(,,,)
B. catch(---)
C. catch(…)
D. catch( void x)
28) Catch handler can have multiple parameters.
A. True
B. False
29) What is the output of this program?
#include<iostream>
using namespace std;
int main()
{
int P = -1;
try {
cout << "Inside try";
if (P < 0)
{
throw P;
cout << "After throw";
}
Unit 5 C++
}
catch (int P )
{
cout << "Exception Caught";
}
cout << "After catch";
return 0;
}
A. Inside try Exception Caught
B. Inside try After throw After catch
C. Inside try Exception Caught After catch
D. Inside try Exception Caught After throw After catch
30) What kind of exceptions are available in c++?
a) handled
b) unhandled
c) static
d) dynamic
31) Identify the correct syntax of catch block.
a) catch(type arg)
{
//Statements for
//managing exceptions
}
b) catch()
{
//Statements for
//managing exceptions
}
c) Catch(type)
{
Unit 5 C++
//Statements for
//managing exceptions
}
d) catch(type)
{
//Statements for
//managing exceptions
};
32) Identify the correct syntax for rethrowing exception.
a) throw;
b) throw(exception);
c) throw exception
d) All of the above
33) Where does the exception are handled?
A. inside the program
B. outside the regular code
C. both a & b
D. none of the mentioned
34) Before object-oriented exception handling was practiced, _____
A. no run-time errors occurred
B. programmers could not deal with run-time errors
C. the most popular error-handling method was to throw an exception
D. the most popular error-handling method was to terminate the program
35) If inner catch block is unable to handle the exception thrown then__________
A. Program stops abnormally
B. The compiler looks for the outer try-catch block
C. The compiler will check for appropriate catch handler of the outer try block
D. The compiler will not check for appropriate catch handler of the outer try block
36) What is the output of the program?
#include<iostream>
using namespace std;
Unit 5 C++
int main()
{
try {
throw 'b';
}
catch (int param)
{
cout << "Int Exception";
}
catch (...) {
cout << "Default Exception";
}
cout << "After Exception";
return 0;
}
A. Int Exception
B. Default Exception
C. Int Exception After Exception
D. Default Exception After Exception
37) In nested try-catch block, if the inner catch block gets executed, then_____________
A. Program stops immediately
B. Outer catch block also executes
C. Compiler jumps to the outer catch block and executes remaining statements of the main() function
D. Compiler executes remaining statements of outer try-catch block and then the main()
function
38) In exception handling, receive the error information means _______________.
a) Handle the exception b) Hit the exception c) Throw the exception d) Catch the exception
39) In exception handling, take corrective actions means _______________.
a) Handle the exception b) Hit the exception c) Throw the exception d) Catch the exception