MCQs
None
It will not throw an exception from the destructor but it will the process by using terminate() function.
As we are calling set_unexpected (myunexpected) function, this is printing as unexpected
called and because of operator compliance it is arising an exception.
Output:
$ g++ etea.cpp
$ a.out
unexpected called
caught int
catch(…) is used to catch all types of exceptions arising in the program.
Output:
$ g++ etea.cpp
$ a.out
Exception occured: exiting
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
In this program, We used a bad type id for the polymorphic operator, So it is arising an
bad_typeid exception.
Output:
$ g++ etae.cpp
$ a.out
exception caught: std::bad_typeid
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.
This catch statement will catch all types of exceptions that arises in the program.
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