January 2019
Intermediate to advanced
512 pages
14h 5m
English
Remember the code at the beginning of the previous section—the one we said is correct, where we did not forget to release the resource? Consider the following code:
bool process(... some parameters ... ) { object_counter* p = new object_counter; ... many more lines of code ... delete p; return true; // Success }
I have bad news for you—this code probably wasn't correct either. If any of the many more lines of code can throw an exception, then delete p is never going to be executed:
bool process(... some parameters ... ) { object_counter* p = new object_counter; ... many more lines of code ... if (!success) // Exceptional circumstances, cannot continue throw process_exception(); ... even more lines ...