Exceptions Flashcards
What are throwing exceptions used for?
Allows for relevant information to be collected and returned as a bundle when something goes wrong (aids debugging)
Should we throw everything?
No. Anything can be thrown but not everything should be thrown.
Why should we throw the relevant derived std::exception.
So that users can program separate catch statements to handle each exception individually. Allows for further debugging.
What can put in the function declaration to indicate it does not throw an exception?
noexcept
What could we do to customise our own exceptions?
- Overriding the what() operation.
- Writing own own functions to provide this information
How would we catch multiple different exceptions?
Using multiple catch blocks.
Why should we use exceptions with resource allocation?
To help clean up resources.
Why should we embrace the RAII? principle?
Allows us to write code that does automatic clean up with exceptions.
Why should we embrace abstractions?
Allows us to rely on the code to sort out memory management.