Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!mstan!jordan From: jordan@Morgan.COM (Jordan Hayes) Newsgroups: comp.lang.c++ Subject: "Failed" constructors Message-ID: <291@zooks.Morgan.COM> Date: 29 Jun 89 18:24:36 GMT Reply-To: jordan@Morgan.COM (Jordan Hayes) Distribution: usa Organization: Morgan Stanley and Co., NY, NY Lines: 28 Is there any convention for how to return from a constructor that has "failed" ... for instance, consider a fascist parent who won't let you look at TV during school hours ... the constructor could check the time of day, and if it's not during school hours, allocate you a TV object, and your code continues. What to do if it's 1pm? Can a constructor "return NULL" so you could say TV *my_tv; if ((my_tv = new TV("HBO")) == NULL) go_read_a_book(); I took a quick look through a bunch of C++ code I have lying around, but couldn't find any exmples of constructors that "return" something. Further, if a constructor decided to "abort" a construction, could the destructor get called? Or, am I doomed to have to write my_tv = new TV("ESPN"); if (my_tv->Valid() == FALSE) { delete my_tv; go_read_a_book(); } Thanks. /jordan