Path: utzoo!attcan!uunet!wuarchive!brutus.cs.uiuc.edu!apple!sun-barr!rutgers!cmcl2!phri!marob!cowan From: cowan@marob.masa.com (John Cowan) Newsgroups: comp.lang.c++ Subject: Re: Handling trouble in C++ Keywords: exception error Message-ID: <24F42DB0.D08@marob.masa.com> Date: 24 Aug 89 17:17:34 GMT References: <13262@well.UUCP> Reply-To: cowan@marob.masa.com (John Cowan) Distribution: comp Organization: ESCC, New York City Lines: 41 In article <13262@well.UUCP> nagle@well.UUCP (John Nagle) writes: > > In C++, unlike C, a considerable fraction of the execution can >take place implicitly, within constructors and destructors, rather >than in explicitly called functions. But there is no way for a >constructor or a destructor to signal an error condition to the ^^^^^^^^^^^^^^^^^^^^^^^^^ >invoker. Declarations aren't allowed to fail. But constructors >often do such things as open files, windows, devices, or databases. >Such operations can fail. What then? This is part of the general C++ weakness in the area of signalling errors. I understand some smart cookies at Bell Labs are thinking about this, but so far without success, due to the very weak and non-portable handling of non-local jumps in the underlying C. What's really needed is something close to the Mesa signalling construct. This is, IMHO, the slickest signal handling around. Mesa allows you to specify something like: catch {block1} using {block2} where block1 is executed, and if a signal(code); statement appears within block1, then block2 gets control. (This is not actual Mesa syntax.) Block2 is typically a switch statement which figures out which signal has been sent. If a signal is not handled by block2, we look further up the stack for higher catchers. Important point: at this time the stack has not been unwound, and it is still possible to return to block1! The options of each case within block2 are: reject the signal, causing a search for higher catchers; return from the signal, which returns a value to the caller of signal() as if nothing special had happened, just a function call; abort, which causes the successor of the catch construct to be executed -- everything from block1 is wiped off the stack; retry, which causes everything from block1 to be wiped off the stack and then block1 is restarted from the beginning. -- Internet/Smail: cowan@marob.masa.com Dumb: uunet!hombre!marob!cowan Fidonet: JOHN COWAN of 1:107/711 Magpie: JOHN COWAN, (212) 420-0527 Charles li reis, nostre emperesdre magnes Set anz toz pleins at estet in Espagne.