Quantcast
Channel: Does C++ support 'finally' blocks? (And what's this 'RAII' I keep hearing about?) - Stack Overflow
Viewing all articles
Browse latest Browse all 17

Answer by SmacL for Does C++ support 'finally' blocks? (And what's this 'RAII' I keep hearing about?)

$
0
0

FWIW, Microsoft Visual C++ does support try,finally and it has historically been used in MFC apps as a method of catching serious exceptions that would otherwise result in a crash. For example;

int CMyApp::Run() {    __try    {        int i = CWinApp::Run();        m_Exitok = MAGIC_EXIT_NO;        return i;    }    __finally    {        if (m_Exitok != MAGIC_EXIT_NO)            FaultHandler();    }}

I've used this in the past to do things like save backups of open files prior to exit. Certain JIT debugging settings will break this mechanism though.


Viewing all articles
Browse latest Browse all 17

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>