Exception Handling
- What is the output of this program?
#include <iostream>
#include <exception>
using namespace std;
class ExceptionExample: public exception
{
virtual const char* what() const throw()
{
return "Exception Occurred...";
}
} NewExcep;
int main ()
{
try
{
throw NewExcep;
}
catch (exception& excep)
{
cout << excep.what() << endl;
}
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We are arising a standard exception and catching that and returning a statement.
- Which is used to check the error in the block?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The try block is used to check for errors, if there is any error means, it can throw it to catch block.
- 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;
void Sequence(int StopN)
{
int N;
N = 3;
while (true)
{
if (N >= StopN)
throw N;
cout << N << endl;
N++;
}
}
int main(void)
{
try
{
Sequence(4);
}
catch(int ExN)
{
cout << "exception: " << ExN << endl;
}
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In this program, We are printing one and raising a exception at 4.