12.1. Base class pointers to derived objects: (Learn C++)
base class pointer to derived objects, can only access function of base class version. So it cannot see the derived class‘s overridden functions inherited from base class itself. It can be handled by virtual function.
If it is happen that exception is not caught by any function, even if by main, the program will be forced to terminate. Then handling the exception is totally dependent on your OS
• catch-all handler: catch(…)
catch-all handler make it possible to catch all exceptions occurred in try block.
To ensure handling the specific exception, it is recommended to put the catch-all handler at last position of try-catch block. * visual studio enforce this constraint
15.5. Exception, Classes and Inheritance: (Learn C++)
• Exception and member functions:
Exception handling, throw-try-catch, can be achieved in member function
* Therefore, errors when occurred in constructing object can be handled by throw-try-catch block. Constructing processed immediately aborted and destructor never executed.
• Exception class:
1. Object of any class type can be thrown as exception parameter
2. Exception class is just a normal class designed specifically to be thrown for dealing with specific context or problem.
* should catch exception class parameter as reference variable for performance
3. std::exception class:
commonly used by C++ standard library classes for exception handling
• Exception Inheritance:
Flow or controlling catch block is sequential.
So, to handle specific derived class, handler for that derived class must be positioned above the base class.
15.6. Exception dangers and Downsides: (Learn C++)
There some issues you should notice before exploiting the exception handling
• Resource Cleaning
if exception occurred before releasing resource i.e. delete pointer, memory issue will happen. So you should implement releasing resource in catch block, or use some functions automatically releasing resource i.e. std::unique_ptr
• Never Throw Exception in Destructor
destructors always called in stack unwinding process. So if you throw the exception in the desturctor, compiler can’t decided whether to continue stack unwinding process or to handle the new exception. The result is to terminate your program immediately
• Exception slow the performance
if function delegate exception handling to caller, then stack unwinding process necessarily need. It will reduce performance of your program. So cautiously exploit exception handling in case of truly exception cases or fatal errors