Strong Exception Safety (8a) Flashcards

1
Q

What is an exception?

A

Design every function to complete successfully or fail in a well-defined manner

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

What is the noexcept specification?

A

Functions that guarantee they will not throw an exception

random: returns true at compile time if(noexcept)

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

What is strong exception safety?

A

General:
Never let go of a piece of information before replacement info is ready for use
Leave objects in a valid state when throwing and re-throwing exception
Use: try-blocks, RAII

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

What is Mutex?

A

Mutual exclusion object
What we need to know:
Makes sure that multiple threads are not using the same resource at once (locks and unlocks)

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

What are the 4 different types of guarantees for exception safe functions?

A

1) No safety Guarantee
2) Basic guarantee: if an exception is thrown, everything in the function remains in a valid state
3) Strong guarantee: if an exception is thrown, the state of the program is unchanged
4) Nothrow guarantee: always works as designed and never throws exceptions

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

What does copy and swap do?

A

Copy original object, modify, if modifications are successful –> swap
exception safe way to alter object

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

What is RAII?

A
  • Only code guaranteed to be executed after an exception is thrown are the destructors of objects on the stack
  • Resource are tied to the lifespan of the objects
  • Vital so that resources are released before permitting exceptions to propagate
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the golden rule of exception handling?

A

When an exception is propagated, try to leave the object in the state it had when the function was called
If not try to make the state as good as possible or call destructors

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