0

Exception Handling, Miscellaneous

Attempted 0/20 Correct 0 Score 0

In exception handling, which block throws an exception?

  1. Catch

  2. Throw

  3. Throws

  4. Try


Correct Option: D
Explanation:

The 'try' block can throw an exception. The catch block catches and processes the exception. 

An exception is a _____________.

  1. compile time error

  2. runtime error

  3. infinite loop

  4. none of these


Correct Option: B
Explanation:

An exception is an unwanted event that occurs during runtime and terminates the execution. Hence, an exception is nothing but a runtime error.

Which of the following is not an example of exception?

  1. Wrongly written inbuilt function

  2. Divide by zero error

  3. Array out of index error

  4. File not found error


Correct Option: A
Explanation:

Wrongly written inbuilt function gives the error in compile time. All the rest are runtime errors. 

In C++, the character type wchar_t is used to hold _______ wide character.

  1. 8 - bit

  2. 16 - bit

  3. 32 - bit

  4. 64 - bit


Correct Option: B
Explanation:

The new data type wchar_t in C++ is used to hold 16 - bit wide character. 

Which of the following statements is used to rethrow an exception?

  1. Throw(exception);

  2. Throw exception;

  3. Throw;

  4. Throws;


Correct Option: C
Explanation:

The statement to rethrow the exception is throw; i.e. throw without any specified exception. 

In order to make the C++ as a generic programming language, Alexander Stepanov and Meng Lee developed a set of general purpose templatised classes and functions. The collection of these classes and functions is called _____________.

  1. Standard Library(SL)

  2. Standard Template Library(STL)

  3. Standard Class Library(SCL)

  4. Standard Class and template Library(SCTL)


Correct Option: C
Explanation:

In C++, Standard Template Library(STL) contains the collection of templatised classes and functions. 

Which keyword allows the constant function to modify a particular data item only?

  1. Modify

  2. Mute

  3. Mutable

  4. Change


Correct Option: C
Explanation:

When the member variable is declared as a mutable, any constant function can modify the data items , i.e. it is declared as mutable. 

Which of the following is the correct sequence of statements for handling an error? A. Throw the exception B. Handle the exception C. Hit the exception D. Catch the exception

  1. ABCD

  2. ABDC

  3. BACD

  4. CADB


Correct Option: D
Explanation:

The correct sequence of statements to handle an error is

  1. Hit the exception
  2. Throw the exception
  3. Catch the exception
  4. Handle the exception

________________ is to used to find the exact type of the object using a pointer to the base class.

  1. RTTI

  2. RTIT

  3. RITT

  4. RTTT


Correct Option: A
Explanation:

Using Run Time Type Identification (RTTI), we can find the exact type of the object using a pointer to the base class. 

___________ defines a scope of the identifiers that are used in a program.

  1. Structure

  2. Union

  3. Namespace

  4. Class


Correct Option: D
Explanation:

Name space, a new concept is introduced in C++. Namespace defines a scope of the identifiers that are used in a program. 

When there is a requirement to convert a const(constant) to non-const(non constant), which keyword is to be used?

  1. cast_const

  2. no_const

  3. non_const

  4. const_cast


Correct Option: D
Explanation:

The const_cast can be used to convert a constant to non-constant. It can also be used to convert the data member of a class from the const functions.  

Which of the following statements is/are correct? A. Multiple catch clauses with one try block. B. Catch block only catches the exception.

  1. Only A

  2. Only B

  3. Both A and B

  4. Neither A nor B


Correct Option: A
Explanation:

There will be a multiple catch clause with one try block. The catch block not only catches the exception but it also processes the exception. 

Which of the following statements is/are correct? A. We can create a reference to an array. B. A reference is implicitly treated as constant pointer.

  1. Only A

  2. Only B

  3. Both A and B

  4. Neither A nor B


Correct Option: C
Explanation:

We can always create a reference to an array and also reference is implicitly treated as constant pointer. Because reference to a particular variable cannot point to another variable. 

The exception that is uncaught invokes the function _______.

  1. end()

  2. exit()

  3. terminate()

  4. block()


Correct Option: C
Explanation:

The uncaught exception calls the function terminate().

What is the meaning of following catch block? catch(...) { Statements; }

  1. Handle any exception that is not caught by other handlers

  2. Handle all I/O exceptions

  3. Handle all exceptions

  4. None of these


Correct Option: A
Explanation:

The ellipsis (...) is used by catch statement to handle all those exceptions that are not caught by other handlers. 

Which of the following statements is/are correct? A. A destructor does not return any value. B. A destructor accepts any number of parameters.

  1. Both are true.

  2. Both are false.

  3. A is true and B is false.

  4. A is false and B is true.


Correct Option: C
Explanation:

It is true that destructor does not return any value but a destructor does not accept any parameter. Hence, destructor cannot be overloaded.

When will the bad_alloc exception be thrown by a program?

  1. Thrown by pointer on allocation failure

  2. Thrown by new operator on allocation failure

  3. Thrown by wrong allocation of data type

  4. Thrown by cin and cout


Correct Option: B
Explanation:

When we are allocating the memory using new operator and allocation fail, then bad_alloc exception is thrown by the program. 

Which one is equivalent to the following statements? (I) #define abc(x) #x (II) cout<<abc(test);

  1. cout<<test;

  2. cout<<abc(#test);

  3. cout<<abc(“test”);

  4. cout<<”test”;


Correct Option: D
Explanation:

The given statements simply print the word “test”, #define abc(x) #x cout<<abc(test); is equivalent to cout<<”Test”;

All exception thrown by the C++ standard library is derived from _____________ class.

  1. ios::exception

  2. stdlib::exception

  3. std::exception

  4. err::exception


Correct Option: C
Explanation:

All the exception thrown by the C++ standard library is derived from the std::exception class. The standard exceptions are bad_alloc, bad_cast, bad_exception, bad_typeid. 

Match the following:

Data type Size in Bytes
1. Int A. 1
2. Long int B. 2
3. Char C. 10
4. Long double D. 4
  1. 1 - B, 2 - D, 3 - A, 4 - C

  2. 1 - D, 2 - B, 3 - A, 4 - C

  3. 1 - B, 2 - A, 3 - D, 4 - C

  4. 1 - B, 2 - D, 3 - C, 4 - A


Correct Option: A
Explanation:

The correct matching pairs ar ||| |---|---| | Data type| Size in Bytes| |

1. Int
| B. 1| |
2. Long int
| D. 2| |
3. Char
| A. 10| |
4. Long double
| C. 4|  

- Hide questions