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;
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.
- What is the output of this program?
#include <iostream>
using namespace std;
void Example(int num)
{
try
{
if (num > 0)
throw num;
else
throw 'U';
}
catch(int num)
{
cout<<"Integer: "<< num << endl;
}
catch(char ch)
{
cout << "Character: " << ch;
}
}
int main()
{
Example(12);
Example(0);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
We are passing the integer and character and catching it by using multiple catch statement.
- What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
int n1 = 20, n2 = 30, n3 = 60;
float Res;
try
{
if ((n1 - n2) != 0)
{
Res = n3 / (n1 - n2);
cout << Res;
}
else
{
throw(n1 - n2);
}
}
catch (int k)
{
cout<<"Answer is infinite..."<< k;
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
We are manipulating the values, if there is any infinite value means, it will raise an exception.