Owen wrote:
I'm a C++ nut.
Why do I say this? Because I have a standardised method of handling errors:
throw AnException();
I have a very "don't repeat yourself" attitude. Thats why I make pervasive use of RAII: For every resource managed by RAII, that's one less thing to go wrong. I love RAII: It really does result in a simplification of program code. It's not perfect, but it's close. Outside C++ (and Objective-C*), Go is probably the language which comes closest with Goroutines, but it still takes code on top of the normal program flow to handle cleanup.
I reserve catch blocks for *handling* exceptions: in general, I find their use to handle *cleanup* is in general a mistake, as it indicates that the lifetime of a resource is encoded in the program's behaviour rather than in its structure.
That said, RAII on its own isn't a panacea: it fails to handle cases involving mutable state on its own. However, it gets you at least 75% of the way, because most state change is resource acquisition or release, and most of the time you can get the next 15% of the way by restructuring things so that you acquire resources up front and then "commit them" with state changes at the end.
Still, I think that most of the time exception handling beats error code returns for cleanliness and code clarity. Some people say they dislike it, because it "hides behaviour from you", but I think that its mostly a matter of being used to error code handling. You have to get used to the change in structure from "Do something, then if that fails, undo it" to "Do something, then commit the results"
* Through it's almost-identical-to-C++ exception model and NSAutoreleasePool
Out of interest, how have you solved the "exceptions aren't kernel thread reentrant" problem?