Exception Handling Flashcards
What is an indication of a problem that occurs during program’s execution?
An exception
What does exception handling do?
Creates applications to resolve exceptions, perform cleanup, notify, and terminate programs
What virtual function does class exception provide to return error message?
what
Which header defines runtime_error?
<stdexcept>
</stdexcept>
What is the termination model of exception handling used by C++?
Control resumes to first statement after catch handler following try block
What is a try block?
Defines a block of code in which exceptions might occur
What follows a try block?
Atleast one catch handler
What do you call the point in the program at which an exception occurs?
Throw point
If exception occurs in a try block, try block expires and control transfers to first….
Catch with same parameter type
Catch handlers should be in what order?
Most specific to least specific
Stack unwinding?
Program terminates function and tries to locate try block in calling function when try has no catch
Exception object
When operand of a throw is an object
When exception handlers defers exception handling to another exception handler
Rethrowing the exception
Common types of exceptions?
Out of range array subscripts
Arithmetic overflow
Division by zero
Invalid function parameters
Unsuccessful memory allocations
Stack unwinding
Function where exception was not terminates and control returns to statement originally invoked
What type of error is exception handling for?
Synchronous errors
What is an asynchronous event?
Errors that occur in parallel with and independent of the programs flow of control
How to declare if a function does not throw any exceptions?
noexcept
Exceptions thrown by constructors cause….
Destructors on all objects
Automatic objects constructed in try blocks are ____________ before an exception is thrown
Destructed
When does stack unwinding complete?
Before exception handler begins executing
What is when a destructor is invoked instead of leaking memory?
Resource allocation is initialization
When operator new fails it throws….
bad_alloc exception
When does new return a pointer to that memory?
When it allocates memory successfully
When can a memory leak occur?
After successful memory allocation but before delete statement executes
Which STL class deals with memory leaks?
unique_ptr
unique_pointer does what?
Destructor performs delete on pointers data member
Which operators does unique_pointer have?
- ->
Copy constructor
Overloaded assignment operator