|
From: Michael C. <jd...@ho...> - 2001-09-05 16:31:25
|
I'm not sure if you got my reply so I'll send it again. The standard states the the first block following the try is the function block. From that I take it that the constructors body ends there. However, the catch is associated and is also deemed part of the constructor, and can be deemed part of the constructors body. Also, the try in this specification has no try-block. Conclusion, I would argue that the last brace of the first block is the end of the constructors body as you do not necessarily need the catch block. What do you think ? Michael >From: "Ioannis Vranos" <no...@ya...> >To: "Dev-C++" <dev...@li...> >Subject: RE: [Dev-C++] C++ question >Date: Wed, 5 Sep 2001 17:14:46 +0200 > >I know all that. My question was if tthe body of the constructor ended >at the end of the catch() block or at the end of the try block. I assume >the end of catch() block so far. > > > > >Warm regards, >Ioannis > >* Ioannis Vranos >* Programming pages: http://www.noicys.f2s.com >* Alternative URL: http://run.to/noicys > > > > -----Original Message----- > > From: Michael Codadeen [mailto:jd...@ho...] > > Sent: Wednesday, September 05, 2001 9:59 AM > > To: no...@ya...; dev...@li... > > Subject: Re: [Dev-C++] C++ question > > > > > > Hi, > > > > I've just been speaking to some grus and they tell me this is > > a new feature > > in the standards to catch exceptions in constructors. > > > > Before constructors are invoked the variables of the class > > are initialised. > > If any throw an exception they are not caught. With this new method > > exceptions are caught. > > > > This is not entirely true as you can have pointers > > initialised to 0, and > > then within the braces have a try/catch to assign something to them. > > However, this feature is to be used with the initialiser list. > > > > I suppose this aids 'resource allocation is initialisation' > > that Strousroup > > talks about (i.e. auto pointers). As you know, in this case > > resources are > > able to be freed if a class constructor throws an exception > > on construction > > and doesn't catch it. > > > > Hope this helps, > > > > Michael > > > > > > >From: "Ioannis Vranos" <no...@ya...> > > >To: "Dev-C++" <dev...@li...> > > >Subject: [Dev-C++] C++ question > > >Date: Wed, 5 Sep 2001 06:24:36 +0200 > > > > > >If anyone knows, please answer. > > > > > >The question is about exception handling caught by a > > constructor. Here > > >is the code: > > > > > >class X > > >{ > > >Vector v; > > >// ... > > > > > >public: > > >X(int); > > >// ... > > >}; > > > > > >X::X(int s) try :v(s) // initialize v by s > > >{ > > >// ... > > >} > > > > > >catch(Vector::Size) > > >{ > > >// exceptions thrown for v are caught here > > > > > >//... > > >} > > > > > >------------------------------------------------------------- > > ---------- > > >- > > >-------------------------------------------- > > > > > >This is from the bible. The question here is, the constructor's body > > >ends at the end of catch body? if not, catch() belongs to where. > > > > > >This style compiles only for constructors defined outside of their > > >class. For the non-believers code that compiles: > > > > > >#include <iostream> > > > > > >class Exception {}; > > > > > >class Vector > > >{ > > >int size; > > >public: > > >Vector(int s):size(s) {} > > >}; > > > > > >class X > > >{ > > >Vector v; > > >public: > > >X(int); > > > > > >}; > > > > > >X::X(int s) try :v(s) > > >{ > > >std::cout<<"code run!\n"; > > > > > >throw Exception(); > > > > > >} > > > > > > catch(Exception) > > > { > > > std::cout<<"Exception caught!\n"; > > > > > > > > > } > > > > > > > > >int main() > > >{ > > >X a(7); > > >} > > > > > >------------------------------------------------------------- > > ---------- > > >- > > >-------------------------------------------- > > > > > > > > > > > >Regards, > > >Ioannis > > > > > >* Ioannis Vranos > > >* Programming pages: http://www.noicys.f2s.com > > ><http://www.noicys.f2s.com/> > > >* Alternative URL: http://run.to/noicys > > > > > > > > > _________________________________________________________________ > > Get your FREE download of MSN Explorer at > > http://explorer.msn.com/intl.asp > > > > >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp |