Why C++ doesn't have the finally keyword

Consider again this snippet of code from the preceding section's "pre-modern" code sample:

    try {      use(*wh);    } catch (...) {      delete wh;      throw;    }    delete wh;

In other languages such as Java and Python, these semantics might be expressed more compactly using the finally keyword:

    try {      use(*wh);    } finally {      delete wh;    }

C++ doesn't have the finally keyword, and shows no signs that it will ever enter the language. This is simply due to a philosophical difference between C++ and those other languages: the C++ philosophy is that if you're concerned with enforcing some invariant--such as "this pointer shall always be freed at the end of this block, no matter how we get there"--then you shouldn't ever be writing ...

Get Mastering the C++17 STL now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.