Does C++ support \'finally\' blocks?
What is the RAII idiom?
What is the difference between C++\'s RAII idiom and C#\'s \'using\' statement?
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.