|
From: Michael C. <jd...@ho...> - 2001-09-05 08:14:46
|
Hi Look at : http://anubis.dkuug.dk/jtc1/sc22/open/n2356/ example 3. 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 |