+ All Categories
Home > Documents > PART III: Structuring of Computations- Structuring the ... · Refer more questions on exception...

PART III: Structuring of Computations- Structuring the ... · Refer more questions on exception...

Date post: 02-May-2018
Category:
Upload: vonhi
View: 216 times
Download: 4 times
Share this document with a friend
17
SNJB’s KBJ COE, Chandwad Department of Computer Engineering 1 PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case Study-Exception handling in C++. ((MARKS)) (1/2/3...) 1 ((QUESTIO N)) An exception is thrown using _____________ keyword in ((OPTION_ A)) throws ((OPTION_ B)) throw ((OPTION_ C)) threw ((OPTION_ D)) thrown ((CORRECT _CHOICE)) (A/B/C/D) B ((EXPLANA TION)) (OPTIONAL ) None ((MARKS)) (1/2/3...) 1 ((QUESTIO N)) ((OPTION_ A)) try
Transcript

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

1

PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case Study-Exception handling in C++.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

An exception is thrown using _____________ keyword in

CPP.

((OPTION_

A)) throws

((OPTION_

B))

throw

((OPTION_

C))

threw

((OPTION_

D))

thrown

((CORRECT

_CHOICE))

(A/B/C/D)

B

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

((OPTION_

A))

try

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

2

((OPTION_

B))

catch

((OPTION_

C))

finally

((OPTION_

D))

None

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Exception handlers are declared with ____________

keyword

((OPTION_

A))

try

((OPTION_

B))

catch

((OPTION_

C))

finally

((OPTION_

D))

None

((CORRECT

_CHOICE))

(A/B/C/D)

B

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

3

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Catch handler can have multiple parameters.

((OPTION_

A))

True

((OPTION_

B))

False

((OPTION_

C))

((OPTION_

D))

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO Which of the following statements are true about Catch \

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

4

N)) handler ?

1. It must be placed immediately after try block T

2. It can have multiple parameters

3. There must be only one catch handler for every try

block

4. There can be multiple catch handler for a try block T

5. Generic catch handler can be placed anywhere after

try block.

((OPTION_

A))

Only 1, 4, 5

((OPTION_

B))

Only 1, 2, 3

((OPTION_

C))

Only 1, 4

((OPTION_

D))

Only 1, 2

((CORRECT

_CHOICE))

(A/B/C/D)

C

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

A try block can be nested under another try block –

((OPTION_ Yes

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

5

A))

((OPTION_

B))

No

((OPTION_

C))

((OPTION_

D))

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

In nested try blocks, there is no need to specify catch

handler for inner try block. Outer catch handler is

sufficient for the program.

a. True

b. False

((OPTION_

A))

True

((OPTION_

B))

False

((OPTION_

C))

((OPTION_

D))

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

6

((CORRECT

_CHOICE))

(A/B/C/D)

B

((EXPLANA

TION))

(OPTIONAL

)

For every try block, there must be at least one catch hander.

Otherwise, compiler will generate error.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

In nested try block, if inner catch handler gets executed,

then______________

((OPTION_

A))

Program execution stops immediately

((OPTION_

B))

Outer catch handler will also get executed

((OPTION_

C))

Compiler will jump to the outer catch handler and then

executes remaining executable statements of main()

((OPTION_

D))

Compiler will execute remaining executable statements of

outer try block and then the main()

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

Compiler will execute remaining executable statements of

outer try block and then the main()

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

7

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

If inner catch handler is not able to handle the exception

then__________

((OPTION_

A))

Compiler will look for outer try handler

((OPTION_

B))

Program terminates abnormally

((OPTION_

C))

Compiler will check for appropriate catch handler of outer

try block

((OPTION_

D))

None of these

((CORRECT

_CHOICE))

(A/B/C/D)

C

((EXPLANA

TION))

(OPTIONAL

)

Compiler will check for appropriate catch handler of outer

try block

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Generic catch handler must be placed at the end of all the

Catch handlers . Tr

((OPTION_

A))

True

((OPTION_

B))

False

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

8

((OPTION_

C))

((OPTION_

D))

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Generic catch handler is represented by ______________

((OPTION_

A))

catch(..,)

((OPTION_

B))

catch(---)

((OPTION_

C))

catch(…)

((OPTION_

D))

catch( void x)

((CORRECT

_CHOICE))

(A/B/C/D)

C

((EXPLANA

TION))

(OPTIONAL

None

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

9

)

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

In nested try blocks, if both inner and outer catch

handlers are not able to handle the exception,

then______________

((OPTION_

A))

Compiler executes only executable statements of main()

((OPTION_

B))

Compiler issues compile time errors about it

((OPTION_

C))

Program will be executed without any interrupt

((OPTION_

D))

Program will be terminated abnormally

((CORRECT

_CHOICE))

(A/B/C/D)

D

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Functions called from within a try block may also throw

exception

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

10

((OPTION_

A))

True

((OPTION_

B))

False

((OPTION_

C))

((OPTION_

D))

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Irrespective of exception occurrence, catch handler will

always get executed.

((OPTION_

A))

True

((OPTION_

B))

False

((OPTION_

C))

((OPTION_

D))

((CORRECT

_CHOICE))

(A/B/C/D)

B

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

11

((EXPLANA

TION))

(OPTIONAL

)

Catch handler will only get execute when exception occurs

at runtime

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Throwing an unhandled exception causes standard library

function _______________ to be invoked.

((OPTION_

A))

stop()

((OPTION_

B))

aborted()

((OPTION_

C))

terminate()

((OPTION_

D))

abandon()

((CORRECT

_CHOICE))

(A/B/C/D)

C

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

An exception can be of only built-In type.

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

12

((OPTION_

A))

True

((OPTION_

B))

False

((OPTION_

C))

((OPTION_

D))

((CORRECT

_CHOICE))

(A/B/C/D)

B

((EXPLANA

TION))

(OPTIONAL

)

An exception can be of any type, including class type that

we create.

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

How can we restrict a function to throw certain exceptions?

((OPTION_

A))

Defining multiple try and catch block inside a function

((OPTION_

B))

Defining generic function within try block

((OPTION_

C))

Defining function with throw clause

((OPTION_

D))

It is not possible in C++ to restrict a function

((CORRECT

_CHOICE))

C

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

13

(A/B/C/D)

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Attempting to throw an exception that is not supported by a

function call results in calling _____________ library

function.

((OPTION_

A))

indeterminate()

((OPTION_

B))

unutilized()

((OPTION_

C))

unexpected()

((OPTION_

D))

unpredicted()

((CORRECT

_CHOICE))

(A/B/C/D)

C

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

14

((QUESTIO

N))

Return type of uncaught_exception() is________________

((OPTION_

A))

int

((OPTION_

B))

bool

((OPTION_

C))

char *

((OPTION_

D))

double

((CORRECT

_CHOICE))

(A/B/C/D)

B

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Can we write throw clause inside catch handler?

((OPTION_

A))

Yes

((OPTION_

B))

No

((OPTION_

C))

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

15

((OPTION_

D))

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

None

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

Can we define our exceptions in CPP? b. No

((OPTION_

A))

Yes

((OPTION_

B))

No

((OPTION_

C))

((OPTION_

D))

((CORRECT

_CHOICE))

(A/B/C/D)

A

((EXPLANA

TION))

(OPTIONAL

)

None

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

16

((MARKS))

(1/2/3...)

1

((QUESTIO

N))

What is the output of this program?

#include <iostream>

using namespace std;

int main()

{

int x = -1;

try

{

if (x < 0)

{

throw x;

}

else

{

cout<<x;

}

}

catch (int x )

{

cout << "Exception occurred: Thrown value is " <<

x << endl;

}

return 0;

}

((OPTION_

A))

-1

((OPTION_

B))

0

((OPTION_

C))

Exception Occurred: Thrown value is -1

((OPTION_ error

SNJB’s KBJ COE, Chandwad Department of Computer Engineering

17

D))

((CORRECT

_CHOICE))

(A/B/C/D)

C

((EXPLANA

TION))

(OPTIONAL

)

As the given value is -1 and according to the condition, We

are arising an exception.

Refer more questions on exception handling in C++ of last OOP MCQs


Recommended