Exception Handling Flashcards

1
Q

What is an indication of a problem that occurs during program’s execution?

A

An exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does exception handling do?

A

Creates applications to resolve exceptions, perform cleanup, notify, and terminate programs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What virtual function does class exception provide to return error message?

A

what

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which header defines runtime_error?

A

<stdexcept>
</stdexcept>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the termination model of exception handling used by C++?

A

Control resumes to first statement after catch handler following try block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a try block?

A

Defines a block of code in which exceptions might occur

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What follows a try block?

A

Atleast one catch handler

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What do you call the point in the program at which an exception occurs?

A

Throw point

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

If exception occurs in a try block, try block expires and control transfers to first….

A

Catch with same parameter type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Catch handlers should be in what order?

A

Most specific to least specific

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Stack unwinding?

A

Program terminates function and tries to locate try block in calling function when try has no catch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Exception object

A

When operand of a throw is an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When exception handlers defers exception handling to another exception handler

A

Rethrowing the exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Common types of exceptions?

A

Out of range array subscripts
Arithmetic overflow
Division by zero
Invalid function parameters
Unsuccessful memory allocations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Stack unwinding

A

Function where exception was not terminates and control returns to statement originally invoked

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What type of error is exception handling for?

A

Synchronous errors

17
Q

What is an asynchronous event?

A

Errors that occur in parallel with and independent of the programs flow of control

18
Q

How to declare if a function does not throw any exceptions?

A

noexcept

19
Q

Exceptions thrown by constructors cause….

A

Destructors on all objects

20
Q

Automatic objects constructed in try blocks are ____________ before an exception is thrown

A

Destructed

21
Q

When does stack unwinding complete?

A

Before exception handler begins executing

22
Q

What is when a destructor is invoked instead of leaking memory?

A

Resource allocation is initialization

23
Q

When operator new fails it throws….

A

bad_alloc exception

24
Q

When does new return a pointer to that memory?

A

When it allocates memory successfully

25
Q

When can a memory leak occur?

A

After successful memory allocation but before delete statement executes

26
Q

Which STL class deals with memory leaks?

A

unique_ptr

27
Q

unique_pointer does what?

A

Destructor performs delete on pointers data member

28
Q

Which operators does unique_pointer have?

A
  • ->
    Copy constructor
    Overloaded assignment operator