This is a try block function, and it is completely legal.
See, for example, here .
The only time you can do something in a function, try to block what you cannot do in a regular try block in a function, this is a catch exception expressed by an expression in the list of constructor initializers (and even then you should end up throwing something- then), but this is not applicable here.
This GOTW # 66 is especially interesting, although it focuses more on designers. It contains this "moral":
Since destructors should never throw an exception, the destructor-function-try-blocks has no practical use at all.
To add clarification, the code as written will throw any exception due to ISO / IEC 14882: 2003 15.3 [except.handle] / 16:
Exception An exception is thrown if the control reaches the end of the handler function of the constructor or destructor block function. [...]
However, it is legal to have a parameterizable return in the handler of the try block function for the destructor - this is forbidden only in the try block function for the constructor - and this will suppress the repeated exception. Thus, any of these alternatives will prevent the exception from being thrown from the destructor.
File::~File() try { Clear(); } catch (...) { Log("caught exception"); return; }
File::~File() { try { Clear(); } catch (...) { Log("caught exception"); } }
source share