Path: utzoo!attcan!uunet!ginosko!usc!ucsd!ucrmath!proton!meson!nusbaum From: nusbaum@meson.uucp (R. James Nusbaum) Newsgroups: comp.lang.c++ Subject: Re: Handling trouble in C++ Keywords: exception error Message-ID: <463@proton.UUCP> Date: 24 Aug 89 21:20:15 GMT References: <13262@well.UUCP> Sender: news@proton.UUCP Reply-To: nusbaum@meson.UUCP (R. James Nusbaum) Distribution: comp Organization: Loma Linda U. Rad. Research Lab, Loma Linda Lines: 28 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? > > > John Nagle One solution I used was to define a signal (SIGUSR1) as the 'constructor failed' signal. Then my constructors would raise this signal whenever they failed while initializing an object on the stack. The user could then define a signal handler for this signal or just let the signal halt the program. Obviously this won't work on systems without signals and I believe the method used by constructors to determine if the object was on the stack was also not very portable. Jim Nusbaum Radiation Research Laboratory Loma Linda University Medical Center nusbaum%proton.uucp@ucrmath.ucr.edu