In this program, We are calling set_unexpected and myfunction, So it is printing the output as the given. Output: $ g++ etae.cpp $ a.out unexpected handler called caught bad_exception
In this program, We are calling set_unexpected and myfunction, So it is printing the output as the given. Output: $ g++ etae.cpp $ a.out unexpected handler called caught bad_exception
Which type of program is recommended to include in try block?
static memory allocation
dynamic memory allocation
const reference
pointer
Explanation:-
Answer: Option B. -> dynamic memory allocation
While during dynamic memory allocation, Your system may not have sufficient resources to
handle it, So it is better to use it inside the try block.
Question 9.
Which statement is used to catch all types of exceptions?
catch()
catch(Test t)
catch(----)
none of the mentioned
Explanation:-
Answer: Option C. -> catch(----)
This catch statement will catch all types of exceptions that arises in the program.
Question 10.
What is the output of this program?
1. #include 2. using namespace std; 3. int main() 4. { 5. int x = -1; 6. try 7. { 8. if (x < 0) 9. { 10. throw x; 11. } 12. else 13. { 14. cout
-1
0
Exception occurred: Thrown value is -1
error
Explanation:-
Answer: Option C. -> Exception occurred: Thrown value is -1
As the given value is -1 and according to the condition, We are arising an exception. Output: $ g++ etae.cpp $ a.out Exception occurred: Thrown value is -1