Re: Re: [OT] C++ coding

>titled “c++ tutoring for Maxim et al”. It simply fixes Maxim’s code where he illustrated exceptions

Just plain and simple: C++ exceptions are a defunct toy without RAII.

I know lots of C++ developers (myself included :slight_smile: I was a COM guy in late 1990ies) and teams. Among them, not more then 10% really go the “heavy proper use of RAII” way. Others consider RAII as distasteful, due to a) lots of non-product-feature-carrying code to write b) no explicit points of destruction, not so important for memory and handles but very important for locks.

And, surely, these RAII-non-users do not use C++ exceptions. Mostly, they use the same language subset that COM uses (even if they do not use COM itself, they usually have their analog of COM - i.e. QI and refcounts - for UNIXen and such).

Also note that proper support of “auto/shared/unique” RAII refs requires rvalue ref support in language syntax (unless you want to have a dramatic perf hit), and this is a very new and recent thing. For MS’s compiler, this is VC++ 2010.

It is good if the object itself has a refcount inside it, like the COM one. In this case, you can only use shared-kind of RAII refs (like the MS’s _com_ptr_t) and relax. Worse if the object has no such thing, like the handle or the allocated memory pointer.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com