Exception Handling
- Where exception are handled?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
outside the regular code
- How many parameters does the throw expression can have?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
In c++ program, We can be able to throw only one error at a time.
- What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
try
{
throw 13;
}
catch (int ex)
{
cout << "Exception number: " << ex << endl;
return 0;
}
cout << "No any Exception..." << endl;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
If we caught a integer value means, there will be an exception, if it is not a integer, there will not be a exception.
- What is the output of this program?
#include <iostream>
#include <exception>
using namespace std;
struct NewException : public exception
{
const char * what () const throw ()
{
return "Interview Mania";
}
};
int main()
{
try
{
throw NewException();
}
catch(NewException& e)
{
cout << "Exception Caught..." << std::endl;
cout << e.what() << std::endl;
}
catch(std::exception& e)
{
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
We are defining the user-defined exception in this program.
- What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
double num1 = 9, num2 = 3, Result;
char Operator = '/';
try
{
if (num2 == 0)
throw "Division by zero not allowed";
Result = num1 / num2;
cout << num1 << " / " << num2 << " = " << Result;
}
catch(const char* S)
{
cout << "\n Bad Operator: " << S;
}
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We are dividing the two variables and printing the result. If any one of the operator is zero means, it will arise a exception.