MCQs
None.
As a constructor don't have a return type, We have to throw the exception.
We are finding the square root of the number, if it is a positive number, it can manipulate, Otherwise
it will arise a exception.
Output:
$ g++ goe4.cpp
$ a.out
2.236
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main()
5.
{
6.
double Op1 = 10, Op2 = 5, Res;
7.
char Op;
8.
try
9.
{
10.
if (Op != '+' && Op != '-' && Op != '*' && Op != '/')
11.
throw Op;
12.
switch(Op)
13.
{
14.
case '+':
15.
Res = Op1 + Op2;
16.
break;
17.
case '-':
18.
Res = Op1 - Op2;
19.
break;
20.
case '*':
21.
Res = Op1 * Op2;
22.
break;
23.
case '/':
24.
Res = Op1 / Op2;
25.
break;
26.
}
27.
cout
It will arise a exception because we missed a operator.
Output:
$ g++ goe3.cpp
$ a.out
is not a valid operator
We are dividing the values and if one of the values is zero means, We are arising an exception.
Output:
$ g++ goe2.cpp
$ a.out
Division by zero condition!
In this program, We are checking the age of a person, If it is zero means, We will arise a exception.
Output:
$ g++ goe1.cpp
$ a.out
5
In this program, We are arising a standard exception and catching that and returning a statement.
Output:
$ g++ goe.cpp
$ a.out
exception arised
In c++ program, We can be able to throw only one error at a time.
none
The try block is used to check for errors, if there is any error means, it can throw it to catch block.