Unit 6: Exception Handling, Templates and Standard Template Library - Subjective Questions

CSE202 — Object Oriented Programming • 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++ using try, throw, and catch.

3

Describe the throwing mechanism in C++. What types of values can be thrown, and what happens after a throw expression is executed?

4

Explain the catching mechanism in C++. Discuss handler matching, handler order, and the catch-all handler.

5

What is stack unwinding during exception handling? Explain its role in resource management.

6

What is rethrowing an exception? Explain how it is performed and identify situations in which it is useful.

7

Design a C++ program that uses a user-defined exception class to validate a bank withdrawal. Explain the flow of exception handling.

8

Define a function template. Explain its syntax, instantiation, and advantages with a suitable example.

9

Explain function-template argument deduction and specialization. How are templates related to overloaded functions?

10

Define a class template and develop a generic Pair class that can store and display two values of potentially different types.

11

Distinguish between function templates and class templates.

12

Explain class templates with inheritance. Illustrate how a template class can derive from another template class.

13

What is the Standard Template Library? Explain the relationship among STL containers, algorithms, and iterators.

14

Classify the main categories of STL containers and give suitable examples of each.

15

Define an iterator. Describe the major iterator categories and the operations supported by them.

16

Explain how STL algorithms operate on iterator ranges. Demonstrate sorting, searching, and counting with a vector.

17

Describe the vector container. Discuss its storage, important member functions, complexity, and iterator invalidation rules.

18

Write and explain a C++ program that performs insertion, deletion, traversal, and sorting on a vector.

19

Describe the list container. Explain its structure, major operations, complexity, and limitations.

20

Compare vector and list. Recommend an appropriate container for different usage scenarios and justify your choices.