Exception Handling
- What is the output of this program?
#include <iostream>
using namespace std;
#include
#include
void Function()
{
cout << "Function() was called by terminate()." << endl;
exit(0);
}
int main()
{
try
{
set_terminate(Function);
throw "Out of memory!";
}
catch(int)
{
cout << "Integer exception raised..." << endl;
}
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
As there is no integer in this program, We are printing Function() was called by terminate().
- What will happen when we move to try block far away from catch block?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
compilers may try to move the catch-code far away from the try-code, which reduces the amount of code to keep in cache normally, thus enhancing performance.
- What will happen if an exception that is thrown may cause a whole load of objects to go out of scope?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
It will be added to the overhead