C++ | Exception Handling | Question 8
#include <iostream> using namespace std; class Test { public: Test() { cout << "Constructing an object of Test " << endl; } ~Test() { cout << "Destructing an object of Test " << endl; } }; int main() { try { Test t1; throw 10; } catch(int i) { cout << "Caught " << i << endl; } } |
chevron_right
filter_none
(A)
Caught 10
(B)
Constructing an object of Test Caught 10
(C)
Constructing an object of Test Destructing an object of Test Caught 10
(D) Compiler Error
Answer: (C)
Explanation: When an object is created inside a try block, destructor for the object is called before control is transferred to catch block.
Quiz of this Question
Recommended Posts:
- C++ | Exception Handling | Question 12
- C++ | Exception Handling | Question 11
- C++ | Exception Handling | Question 7
- C++ | Exception Handling | Question 4
- C++ | Exception Handling | Question 5
- C++ | Exception Handling | Question 3
- C++ | Exception Handling | Question 9
- C++ | Exception Handling | Question 10
- C++ | Exception Handling | Question 2
- C++ | Exception Handling | Question 1
- C++ | Exception Handling | Question 6
- Java | Exception Handling | Question 8
- Java | Exception Handling | Question 8
- Java | Exception Handling | Question 2
- Java | Exception Handling | Question 3
Improved By : mayank5326



