|
From: Ioannis V. <no...@ya...> - 2001-09-05 18:17:14
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Michael Codadeen
> Sent: Wednesday, September 05, 2001 6:31 PM
> To: no...@ya...; dev...@li...
> Subject: RE: [Dev-C++] C++ question
>=20
>=20
> I'm not sure if you got my reply so I'll send it again.
>=20
> The standard states the the first block following the try is=20
> the function=20
> block. From that I take it that the constructors body ends=20
> there. However,=20
> the catch is associated and is also deemed part of the=20
> constructor, and can=20
> be deemed part of the constructors body.
>=20
> Also, the try in this specification has no try-block.
>=20
> Conclusion, I would argue that the last brace of the first=20
> block is the end=20
> of the constructors body as you do not necessarily need the=20
> catch block.
>=20
> What do you think ?
>=20
> Michael
I experimented with Dev-C++ and i concluded that the catch block belongs
to the constructor too. The constructor ends at the end of the catch
block. I guess case is closed...
The code:
#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();
}
=20
catch(Exception)
{
std::cout<<"Exception caught!\n";
std::cout<<s;
this;
}
=20
=20
int main()
{
X a(7);
}
|