You can't do without exceptions unless you're prepared to cut yourself off from quite a swathe of C++That's why there's a mini lecture on alternative error management strategies and a whole one on "Cruel and Unusual Pointers" on the CQF.C&UP tells you about auto_ptr, shared_ptr etc, and this leads to object lifetime mechanism like the singleton pattern.We also deal with the worst bug in the world, a variant of which was given that title by IBM & Microsoft when we were all friends and built operating systems together.Why you can't just have return codes (short version);With operators like  there isn't anywhere to put the return code.The grown up class libraries like Boost and STL use them. MFC doesn't really , and yes the story about me threatening MFC's author with a knife is mostly true.Operator new throws exceptions, fuck me if I know how you deal with that by return codes (OK, I do know how, but I cut that bit from the CQF C++ as being too Cruel and unusual.)It requires the coder using the function to remember to check every return code. Yeah, reckon that happens a lot, and Britney Spears has offered me her body if I debug some of her floating point code.But let us look at the worst bug in the world.The most common way of returning an error is demonstrated in malloc, which either returns 0 or a pointer to newly allocated memory.ie you use an "impossible" value.So how do you deal with numeric function that gets passed "wrong" values ?Yep, you pass back another "wrong" value.But as above, it's not always checked, and it's "obviously wrong value, can get sucked into a calculation that make it right.Try tracing that one down.Even the pointer shit can blow up in your face.double * a = reinterpret_cast<double *> malloc(sizeof (double) *100);*a = 42;Will die, butdouble *pa = a+ index;*pa = 42;May die, it may not will cause corruption, or not.
Last edited by DominicConnor
on May 28th, 2007, 10:00 pm, edited 1 time in total.