Exceptions and Memory (4) Flashcards

1
Q

What is the purpose of exception handling?

A

Permit the program to catch and handle errors, rather than let the error occur and suffer the consequences.

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

What is a try block?

A

It encloses code that may generate an error and produce and exception
Use as few as possible

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

What is a catch block?

A

Follows a try block
Specifies the type of exception it can catch and handle
Contains an exception handler

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

What is the terminate function?

A

Calls the abort function that aborts the program

Called if there is no catch block

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

How does throw work with const objects?

A

If a func throws a const object then the catch handler must be declared const as well

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

What is the Data segment of memory?

A

Allocated at compilation time and is of fixed size

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

When is memory allocated in the stack?

A

Automatically managed at run time

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

When is memory allocated in the heap?

A

Explicitly managed by the program

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

What is static memory?

A

Reserved at compile time in data segment
Deallocated when program exits
Ex: Global vars, statics vars, static class members, variables allocated outside of a function or using Static
Automatically set to 0

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

What is automatic memory?

A

Allocated at run time as control flow enters and deallocated as flow exits
Function params, local variables, added to stack and deallocated in reverse order

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

What is dynamic memory?

A

Allocated during run time
Maintained on the memory heap
Requires use of new and delete
More flexible

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

When does a memory leak occur?

A

When memory is allocated from the heap using new but is not returned to the heap using delete

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

What order does delete [] arr delete things?

A

Deallocates in the opposite direction from the allocation (from back to front)

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

What does new operator do?

A

Calls the function operator new to allocate storage

Invokes a constructor to turn the uninitialized storage into an object

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