Unit 6: Handling Exceptions, Templates and STL - Subjective Questions

CAP455 — Object Oriented Programming Using C++ • Practice Questions with Detailed Answers

20 questions

1

Define an exception in C++. Why is exception handling preferred over traditional error-handling techniques?

2

Explain the exception-handling mechanism in C++ with a suitable example.

3

Describe the throwing exception mechanism in C++. What kinds of values or objects can be thrown?

4

Explain how exceptions are caught in C++. Discuss multiple catch blocks and the catch-all handler.

5

What is stack unwinding? Explain its role during exception propagation.

6

What is re-throwing an exception? Explain its syntax, purpose, and behavior with an example.

7

Differentiate between exception handling and error-code-based handling in C++.

8

Define a function template. Write and explain a C++ function template that returns the larger of two values.

9

Explain template argument deduction, explicit template arguments, and function template overloading.

10

Define a class template. Design a generic Pair class and explain how objects of different specializations are created.

11

Explain class template specialization. Distinguish between full specialization and partial specialization with examples.

12

Discuss the possible relationships between class templates and inheritance in C++. Illustrate template-to-template inheritance with a program.

13

What is the Standard Template Library (STL)? Explain its importance and major components.

14

Classify STL containers and give suitable examples of each category.

15

Explain STL algorithms. Demonstrate the use of sorting, searching, counting, and transformation algorithms on a vector.

16

Define an iterator. Explain the major categories of STL iterators and their capabilities.

17

Distinguish between iterator, const_iterator, and reverse_iterator. Explain iterator invalidation.

18

Describe the vector container in detail. Discuss its important operations, size, capacity, and performance characteristics.

19

Describe the list container in C++. Explain its operations, advantages, limitations, and iterator behavior.

20

Compare the vector and list containers. How should a programmer select between them for a given application?