Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-08-14 14:12:42


From: "Bill Seymour" <bill-at-the-office_at_[hidden]>
>
> What did surprise me is that, when I catch the exception
> in f() by either const or non-const reference, the exception
> still gets sliced. I added a catch(X) block after the
> catch(Y) in main() and the "abnormal program termination"
> became "Caught an X!\n", so slicing really does explain it.
>
> It seems to me that slicing when catching by reference
> is a bug in my implementation; but I can't cite anything
> in the Standard to support that. 8-(

Your implementation is correct. "throw x" throws a copy of x, not x itself,
and a copy of

X const & x;

is a X. So it is "throw x" that slices, not "catch(X const & x)". :-)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk