Xref: utzoo comp.lang.c++:4451 gnu.g++:353 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!gem.mps.ohio-state.edu!ginosko!aplcen!haven!adm!cmcl2!lanl!opus!ted From: ted@nmsu.edu (Ted Dunning) Newsgroups: comp.lang.c++,gnu.g++ Subject: Re: Unwinding vs destructors Message-ID: Date: 22 Aug 89 19:53:00 GMT References: <13145@well.UUCP> <13635@polyslo.CalPoly.EDU> Sender: news@nmsu.edu Followup-To: comp.lang.c++ Distribution: usa Organization: NMSU Computer Science Lines: 43 In-reply-to: ttwang@polyslo.CalPoly.EDU's message of 16 Aug 89 21:09:16 GMT In article <13635@polyslo.CalPoly.EDU> ttwang@polyslo.CalPoly.EDU (Thomas Wang) writes: nagle@well.UUCP (John Nagle) writes: > C++ destructors provide a means to force cleanup of an object as it >disappears upon exit from a scope. Unfortunately, the "longjmp" mechanism >evades destructor processing. "longjmp" is an old hack, only sort of part >of C. But it is useful. Should C++ have a better escape mechanism, >along the lines of "throw" and "return-from" in Common LISP or "raise" in >Ada? With those mechanisms, appropriate cleanup processing is performed >as the scopes unwind. But C++ lacks such a mechanism. I would suggest something like the following: extern int error_code, error_type; ... sample code ... I think this error handling mechanism is fairly explicit, and replaces all instances of ad-hoc error checkings. The mechanism is borrowed from Eiffel if you have not noticed already. i didn't actually notice. i have implemented a unwind_protect/catch/throw mechanism for unadorned c that would be easy to move to c++. this mechanism is based on the semantics of these constructs in common lisp and should provide a robust non-local return mechanism if longjmp is not used. it is probably desirable that an error/debug mechanism be implemented alongside the catch/throw mechanism based on the experience in common lisp. if anyone is interested, i can either post/email the code (it is really pretty small). -- ted@nmsu.edu Most of all, he loved the fall when the cottonwoods leaves turned gold and floated down the trout streams under the clear blue windswept skies.