|
From: Michael C <jd...@ho...> - 2001-09-05 21:33:34
|
O.K. for argument sake I agree with you.
I agree that the catch block is the end of the constructor only when it is
present.
What I would like to know is what happens when you have an initialiser list
of two or more objects that you want to place a try against.
Would you have the following ?
X () try : a(1), b(2), c(3)
{
...
}
How would you determine in the catch who threw the exception ?
I guess each object could throw a different kind of exception and there
could be a catch for each kind. But if they all throw the same kind of
exception I guess you would need some sort of identification in that
exception to correlate it to the offending object.
As I am using an older compiler, HPUX 10.20, I cannot play with this myself.
When I move to HPUX 11, I'll be able to try it out.
Have you tried the above ?
Michael
----- Original Message -----
From: Ioannis Vranos <no...@ya...>
To: Dev-C++ <dev...@li...>
Sent: Wednesday, September 05, 2001 8:18 PM
Subject: RE: [Dev-C++] C++ question
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Michael Codadeen
> Sent: Wednesday, September 05, 2001 6:31 PM
> To: no...@ya...; dev...@li...
> Subject: RE: [Dev-C++] C++ question
>
>
> 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
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();
}
catch(Exception)
{
std::cout<<"Exception caught!\n";
std::cout<<s;
this;
}
int main()
{
X a(7);
}
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|