Topic: deprecate catch exception by value, at least in


Author: David Krauss <potswa@gmail.com>
Date: Mon, 9 Feb 2015 06:55:38 +0800
Raw View
--Apple-Mail=_0F59AFC3-D707-4A25-9BCD-0A3A41FB36B0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9302=E2=80=9309, at 6:42 AM, gmisocpp@gmail.com wrote:
>=20
> A more graphic example  note my_base destructs twice but constructs once:

You=E2=80=99re not seeing the copy (by slice) constructor.

If you don=E2=80=99t want a base exception class to be sliced, you can cons=
ider making it abstract. I don=E2=80=99t really see any problem in getting =
a std::exception value, though.

On the other hand, catching a base class by value gives the catch block its=
 own modifiable copy. This might not be very useful, and might seldom refle=
ct a strong intent of the programmer, but there=E2=80=99s no other way to a=
chieve it than to initialize the parameter by value. Deprecation would seem=
 gratuitous.

> Again no warning. Would anyone ever want this in this circumstance?

I=E2=80=99ve never really wanted a catch by value, but it does give the blo=
ck the opportunity to choose between throwing a modified copy, and re-throw=
ing to resume unwinding without any change.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_0F59AFC3-D707-4A25-9BCD-0A3A41FB36B0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9302=
=E2=80=9309, at 6:42 AM, <a href=3D"mailto:gmisocpp@gmail.com" class=3D"">g=
misocpp@gmail.com</a> wrote:</div><br class=3D"Apple-interchange-newline"><=
div class=3D""><div style=3D"font-family: Helvetica; font-size: 12px; font-=
style: normal; font-variant: normal; font-weight: normal; letter-spacing: n=
ormal; line-height: normal; orphans: auto; text-align: start; text-indent: =
0px; text-transform: none; white-space: normal; widows: auto; word-spacing:=
 0px; -webkit-text-stroke-width: 0px;" class=3D"">A more graphic example&nb=
sp; note my_base destructs twice but constructs once:</div></div></blockquo=
te></div><br class=3D""><div class=3D"">You=E2=80=99re not seeing the copy =
(by slice) constructor.</div><div class=3D""><br class=3D""></div><div clas=
s=3D"">If you don=E2=80=99t want a base exception class to be sliced, you c=
an consider making it abstract. I don=E2=80=99t really see any problem in g=
etting a <font face=3D"Courier" class=3D"">std::exception</font> value, tho=
ugh.</div><div class=3D""><br class=3D""></div><div class=3D"">On the other=
 hand, catching a base class by value gives the catch block its own modifia=
ble copy. This might not be very useful, and might seldom reflect a strong =
intent of the programmer, but there=E2=80=99s no other way to achieve it th=
an to initialize the parameter by value. Deprecation would seem gratuitous.=
</div><div class=3D""><br class=3D""></div><div class=3D""><blockquote type=
=3D"cite" class=3D""><div class=3D"">Again no warning. Would anyone ever wa=
nt this in this circumstance?</div></blockquote><br class=3D""></div><div c=
lass=3D"">I=E2=80=99ve never really wanted a catch by value, but it does gi=
ve the block the opportunity to choose between throwing a modified copy, an=
d re-throwing to resume unwinding without any change.</div></body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_0F59AFC3-D707-4A25-9BCD-0A3A41FB36B0--

.


Author: gmisocpp@gmail.com
Date: Sun, 8 Feb 2015 16:07:49 -0800 (PST)
Raw View
------=_Part_30_1615822702.1423440469492
Content-Type: multipart/alternative;
 boundary="----=_Part_31_53952552.1423440469492"

------=_Part_31_53952552.1423440469492
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Monday, February 9, 2015 at 11:55:51 AM UTC+13, David Krauss wrote:
>
>
> On 2015=E2=80=9302=E2=80=9309, at 6:42 AM, gmis...@gmail.com <javascript:=
> wrote:
>
> A more graphic example  note my_base destructs twice but constructs once:
>
>
> You=E2=80=99re not seeing the copy (by slice) constructor.
>

Yes you are correct. I can see that by adding the piece of the puzzle I=20
failed to add:

    my_base(my_base& other)
    {
        std::printf("my_base copy\n");     =20
    }
 =20

> If you don=E2=80=99t want a base exception class to be sliced, you can co=
nsider=20
> making it abstract.
>
true
=20

> I don=E2=80=99t really see any problem in getting a std::exception value,=
 though.
>
> On the other hand, catching a base class by value gives the catch block=
=20
> its own modifiable copy. This might not be very useful, and might seldom=
=20
> reflect a strong intent of the programmer, but there=E2=80=99s no other w=
ay to=20
> achieve it than to initialize the parameter by value. Deprecation would=
=20
> seem gratuitous.
>
> Again no warning. Would anyone ever want this in this circumstance?
>
>
> I=E2=80=99ve never really wanted a catch by value, but it does give the b=
lock the=20
> opportunity to choose between throwing a modified copy, and re-throwing t=
o=20
> resume unwinding without any change.
>

In summary. you are probably right.

But I remember when I was first learning C++ I had a hard time remembering=
=20
when to throw or catch by value or reference. Now I know to throw by value=
=20
and catch by reference.

But it might have helped if the compiler enforced catching by reference or=
=20
warned if you did not, by default. Then if you really want to slice=20
you could do it explicitly.

It could be seen as gratuitous or it could be seen as a kind of safe by=20
default thing.

So more generally then, In the earlier example:

    my_derived d;
    my_base b;
    b =3D d; // Where useful? Happens without intention more often than not=
?

I guess the question is how often do we slice and why and can it cause harm=
=20
and if so is it something where the default could be improved?

Consulting SO, it seems people wonder and might be left wondering about=20
slicing:
http://stackoverflow.com/questions/2432683/what-does-slicing-mean-in-c

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_31_53952552.1423440469492
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Monday, February 9, 2015 at 11:55:51 AM UTC+13,=
 David Krauss wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0px =
0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); bo=
rder-left-width: 1px; border-left-style: solid;"><div style=3D"-ms-word-wra=
p: break-word;"><br><div><blockquote type=3D"cite"><div>On 2015=E2=80=9302=
=E2=80=9309, at 6:42 AM, <a onmousedown=3D"this.href=3D'javascript:';return=
 true;" onclick=3D"this.href=3D'javascript:';return true;" href=3D"javascri=
pt:" target=3D"_blank" rel=3D"nofollow" gdf-obfuscated-mailto=3D"WasyVVzoW6=
0J">gmis...@gmail.com</a> wrote:</div><br><div><div style=3D"font: 12px/nor=
mal Helvetica; text-transform: none; text-indent: 0px; letter-spacing: norm=
al; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-st=
retch: normal;">A more graphic example&nbsp; note my_base destructs twice b=
ut constructs once:</div></div></blockquote></div><br><div>You=E2=80=99re n=
ot seeing the copy (by slice) constructor.</div></div></blockquote><div><br=
></div><div>Yes you are correct. I can see that by adding the&nbsp;piece of=
 the puzzle I failed to add:</div><div><br></div><div>&nbsp;&nbsp;&nbsp; my=
_base(my_base&amp; other)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; std::printf("my_base copy\n");&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; <br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;<br></div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; bor=
der-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-sty=
le: solid;"><div style=3D"-ms-word-wrap: break-word;"><div>If you don=E2=80=
=99t want a base exception class to be sliced, you can consider making it a=
bstract.</div></div></blockquote><div>true</div><div>&nbsp;</div><blockquot=
e class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1=
ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-l=
eft-style: solid;"><div style=3D"-ms-word-wrap: break-word;"><div> I don=E2=
=80=99t really see any problem in getting a <font face=3D"Courier">std::exc=
eption</font> value, though.</div><div><br></div><div>On the other hand, ca=
tching a base class by value gives the catch block its own modifiable copy.=
 This might not be very useful, and might seldom reflect a strong intent of=
 the programmer, but there=E2=80=99s no other way to achieve it than to ini=
tialize the parameter by value. Deprecation would seem gratuitous.</div><di=
v><br></div><div><blockquote type=3D"cite"><div>Again no warning. Would any=
one ever want this in this circumstance?</div></blockquote><br></div><div>I=
=E2=80=99ve never really wanted a catch by value, but it does give the bloc=
k the opportunity to choose between throwing a modified copy, and re-throwi=
ng to resume unwinding without any change.</div></div></blockquote><div><br=
></div><div>In summary. you are probably right.</div><div><br></div><div>Bu=
t I remember&nbsp;when I was first learning C++&nbsp;I had a hard time reme=
mbering when to throw or catch by value or reference. Now I know to throw b=
y value and catch by reference.</div><div><br></div><div>But&nbsp;it might =
have helped&nbsp;if the compiler enforced catching by reference&nbsp;or war=
ned if you did not, by default. Then if you really want to slice you&nbsp;c=
ould do it explicitly.</div><div><br></div><div>It could be seen as gratuit=
ous or it could be seen as a kind of safe by default thing.</div><div><br><=
/div><div>So more generally then, In the earlier example:</div><div><br></d=
iv><div><div>&nbsp;&nbsp;&nbsp; my_derived d;<br>&nbsp;&nbsp;&nbsp; my_base=
 b;<br>&nbsp;&nbsp;&nbsp; b =3D d; // Where useful?&nbsp;Happens without in=
tention more often&nbsp;than not?</div><div><br></div><div>I guess the ques=
tion is how often&nbsp;do we&nbsp;slice and why and can it cause harm and i=
f so&nbsp;is it something&nbsp;where the&nbsp;default could be&nbsp;improve=
d?</div><div><br></div><div>Consulting SO, it seems&nbsp;people&nbsp;wonder=
 and might be left&nbsp;wondering about slicing:</div><div><a href=3D"http:=
//stackoverflow.com/questions/2432683/what-does-slicing-mean-in-c">http://s=
tackoverflow.com/questions/2432683/what-does-slicing-mean-in-c</a><br></div=
></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_31_53952552.1423440469492--
------=_Part_30_1615822702.1423440469492--

.


Author: David Krauss <potswa@gmail.com>
Date: Mon, 9 Feb 2015 08:28:25 +0800
Raw View
--Apple-Mail=_F851E552-0BAD-402E-B2C4-419214A5361C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9302=E2=80=9309, at 8:07 AM, gmisocpp@gmail.com wrote:
>=20
> But I remember when I was first learning C++ I had a hard time rememberin=
g when to throw or catch by value or reference. Now I know to throw by valu=
e and catch by reference.

Perhaps it=E2=80=99s hard to remember because it doesn=E2=80=99t make much =
of a difference either way. There=E2=80=99s no such thing as throwing by re=
ference, at all. You can get a little extra efficiency by using std::move w=
hen throwing, but there=E2=80=99s not really much point. (Eh, perhaps it ad=
ds some memory safety against bad_alloc.) Likewise, the overhead of making =
a copy for a catch block is usually nothing compared to the unwinding itsel=
f.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_F851E552-0BAD-402E-B2C4-419214A5361C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9302=
=E2=80=9309, at 8:07 AM, <a href=3D"mailto:gmisocpp@gmail.com" class=3D"">g=
misocpp@gmail.com</a> wrote:</div><br class=3D"Apple-interchange-newline"><=
div class=3D""><div style=3D"font-family: Helvetica; font-size: 12px; font-=
style: normal; font-variant: normal; font-weight: normal; letter-spacing: n=
ormal; line-height: normal; orphans: auto; text-align: start; text-indent: =
0px; text-transform: none; white-space: normal; widows: auto; word-spacing:=
 0px; -webkit-text-stroke-width: 0px;" class=3D"">But I remember&nbsp;when =
I was first learning C++&nbsp;I had a hard time remembering when to throw o=
r catch by value or reference. Now I know to throw by value and catch by re=
ference.</div></div></blockquote></div><br class=3D""><div class=3D"">Perha=
ps it=E2=80=99s hard to remember because it doesn=E2=80=99t make much of a =
difference either way. There=E2=80=99s no such thing as throwing by referen=
ce, at all. You can get a little extra efficiency by using <font face=3D"Co=
urier" class=3D"">std::move</font> when throwing, but there=E2=80=99s not r=
eally much point. (Eh, perhaps it adds some memory safety against <font fac=
e=3D"Courier" class=3D"">bad_alloc</font>.) Likewise, the overhead of makin=
g a copy for a <font face=3D"Courier" class=3D"">catch</font> block is usua=
lly nothing compared to the unwinding itself.</div></body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_F851E552-0BAD-402E-B2C4-419214A5361C--

.


Author: gmisocpp@gmail.com
Date: Sun, 8 Feb 2015 17:36:48 -0800 (PST)
Raw View
------=_Part_171_1258179142.1423445808322
Content-Type: multipart/alternative;
 boundary="----=_Part_172_2092851232.1423445808322"

------=_Part_172_2092851232.1423445808322
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Monday, February 9, 2015 at 1:28:33 PM UTC+13, David Krauss wrote:
>
>
> On 2015=E2=80=9302=E2=80=9309, at 8:07 AM, gmis...@gmail.com <javascript:=
> wrote:
>
> But I remember when I was first learning C++ I had a hard time rememberin=
g=20
> when to throw or catch by value or reference. Now I know to throw by valu=
e=20
> and catch by reference.
>
>
> Perhaps it=E2=80=99s hard to remember because it doesn=E2=80=99t make muc=
h of a difference=20
> either way. There=E2=80=99s no such thing as throwing by reference, at al=
l. You can=20
> get a little extra efficiency by using std::move when throwing, but=20
> there=E2=80=99s not really much point. (Eh, perhaps it adds some memory s=
afety=20
> against bad_alloc.) Likewise, the overhead of making a copy for a catch=
=20
> block is usually nothing compared to the unwinding itself.
>

I think in my case the issue was that when I was learning C++ I was=20
confused about pointers and references and values.
i.e. If I threw a pointer was I throwing a copy of the object that I was=20
pointing to, or just the pointer.
Also since I equated references and pointers in my mind it then wasn't=20
clear to me then if I threw something I had a reference to, was I actually=
=20
throwing a pointer still and should I catch it with a pointer or reference=
=20
to handle that.
Add to that, if I catch by value, am I catching my original object thrown=
=20
by value or a copy of it, or a copy of a copy. etc. and you can see why=20
anything that could have stopped me getting into that mental mess might=20
have been good!

Hey that all strangely leads me off to a different idea:
When we throw x, why can't we treat that as a move in some instances, like=
=20
return does!?

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_172_2092851232.1423445808322
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Monday, February 9, 2015 at 1:28:33 PM UTC+13, =
David Krauss wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0=
px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); bor=
der-left-width: 1px; border-left-style: solid;"><div style=3D"-ms-word-wrap=
: break-word;"><br><div><blockquote type=3D"cite"><div>On 2015=E2=80=9302=
=E2=80=9309, at 8:07 AM, <a onmousedown=3D"this.href=3D'javascript:';return=
 true;" onclick=3D"this.href=3D'javascript:';return true;" href=3D"javascri=
pt:" target=3D"_blank" rel=3D"nofollow" gdf-obfuscated-mailto=3D"CudRklv3T8=
UJ">gmis...@gmail.com</a> wrote:</div><br><div><div style=3D"font: 12px/nor=
mal Helvetica; text-transform: none; text-indent: 0px; letter-spacing: norm=
al; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-st=
retch: normal;">But I remember&nbsp;when I was first learning C++&nbsp;I ha=
d a hard time remembering when to throw or catch by value or reference. Now=
 I know to throw by value and catch by reference.</div></div></blockquote><=
/div><br><div>Perhaps it=E2=80=99s hard to remember because it doesn=E2=80=
=99t make much of a difference either way. There=E2=80=99s no such thing as=
 throwing by reference, at all. You can get a little extra efficiency by us=
ing <font face=3D"Courier">std::move</font> when throwing, but there=E2=80=
=99s not really much point. (Eh, perhaps it adds some memory safety against=
 <font face=3D"Courier">bad_alloc</font>.) Likewise, the overhead of making=
 a copy for a <font face=3D"Courier">catch</font> block is usually nothing =
compared to the unwinding itself.</div></div></blockquote><div><br></div><d=
iv>I think in my case&nbsp;the issue was that when I was learning C++&nbsp;=
I was confused about pointers and references and values.</div><div>i.e. If =
I threw a pointer&nbsp;was I throwing a copy of the object that I was point=
ing to, or just the pointer.</div><div>Also since I equated references and =
pointers in my mind&nbsp;it then wasn't clear to me then&nbsp;if I threw so=
mething&nbsp;I had a&nbsp;reference to, was I actually throwing a pointer s=
till and should I catch&nbsp;it with a pointer or reference to handle that.=
</div><div>Add to that, if I catch by value, am I catching my&nbsp;original=
 object thrown by value or a copy of it, or a copy of&nbsp;a copy. etc. and=
 you can see why anything that could have stopped me getting into that ment=
al mess might have been good!</div><div><br></div><div>Hey that all strange=
ly leads me off to a different idea:</div><div>When we throw x, why can't w=
e treat that as a move in some instances, like return does!?</div><div><br>=
</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_172_2092851232.1423445808322--
------=_Part_171_1258179142.1423445808322--

.


Author: David Krauss <potswa@gmail.com>
Date: Mon, 9 Feb 2015 09:52:31 +0800
Raw View
--Apple-Mail=_5F0B1D8C-D7ED-45D5-B2E8-C7B5B499BD9E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9302=E2=80=9309, at 9:36 AM, gmisocpp@gmail.com wrote:
>=20
> I think in my case the issue was that when I was learning C++ I was confu=
sed about pointers and references and values.
> i.e. If I threw a pointer was I throwing a copy of the object that I was =
pointing to, or just the pointer.
> Also since I equated references and pointers in my mind it then wasn't cl=
ear to me then if I threw something I had a reference to, was I actually th=
rowing a pointer still and should I catch it with a pointer or reference to=
 handle that.
> Add to that, if I catch by value, am I catching my original object thrown=
 by value or a copy of it, or a copy of a copy. etc. and you can see why an=
ything that could have stopped me getting into that mental mess might have =
been good!
>=20
> Hey that all strangely leads me off to a different idea:
> When we throw x, why can't we treat that as a move in some instances, lik=
e return does!?

My answer to all this would be that 99% of users will only ever throw prval=
ue expressions of the form

    throw exception_type{ simple, constants };

=E2=80=A6 and although unsafe slicing may occur on catch-by-value, referenc=
es within the sliced base object will tend to refer only into the original =
derived exception, which is safely preserved.

There are users coming from Java who try to put new everywhere, but that=E2=
=80=99s just uniformly wrong.

Throwing expressions of non-class type is a bit silly, but deprecating that=
 sort of thing smacks of playing thought-police.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_5F0B1D8C-D7ED-45D5-B2E8-C7B5B499BD9E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9302=
=E2=80=9309, at 9:36 AM, <a href=3D"mailto:gmisocpp@gmail.com" class=3D"">g=
misocpp@gmail.com</a> wrote:</div><br class=3D"Apple-interchange-newline"><=
div class=3D""><div dir=3D"ltr" class=3D"">I think in my case&nbsp;the issu=
e was that when I was learning C++&nbsp;I was confused about pointers and r=
eferences and values.<br class=3D""><div class=3D"">i.e. If I threw a point=
er&nbsp;was I throwing a copy of the object that I was pointing to, or just=
 the pointer.</div><div class=3D"">Also since I equated references and poin=
ters in my mind&nbsp;it then wasn't clear to me then&nbsp;if I threw someth=
ing&nbsp;I had a&nbsp;reference to, was I actually throwing a pointer still=
 and should I catch&nbsp;it with a pointer or reference to handle that.</di=
v><div class=3D"">Add to that, if I catch by value, am I catching my&nbsp;o=
riginal object thrown by value or a copy of it, or a copy of&nbsp;a copy. e=
tc. and you can see why anything that could have stopped me getting into th=
at mental mess might have been good!</div><div class=3D""><br class=3D""></=
div><div class=3D"">Hey that all strangely leads me off to a different idea=
:</div><div class=3D"">When we throw x, why can't we treat that as a move i=
n some instances, like return does!?</div></div></div></blockquote><br clas=
s=3D""></div><div>My answer to all this would be that 99% of users will onl=
y ever throw prvalue expressions of the form</div><div><br class=3D""></div=
><div><font face=3D"Courier" class=3D"">&nbsp; &nbsp; throw exception_type{=
 simple, constants };</font></div><div><br class=3D""></div><div>=E2=80=A6 =
and although unsafe slicing may occur on catch-by-value, references within =
the sliced base object will tend to refer only into the original derived ex=
ception, which is safely preserved.</div><div><br class=3D""></div><div>The=
re are users coming from Java who try to put <font face=3D"Courier" class=
=3D"">new</font> everywhere, but that=E2=80=99s just uniformly wrong.</div>=
<div><br class=3D""></div><div>Throwing expressions of non-class type is a =
bit silly, but deprecating that sort of thing smacks of playing thought-pol=
ice.</div></body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_5F0B1D8C-D7ED-45D5-B2E8-C7B5B499BD9E--

.


Author: =?UTF-8?Q?David_Rodr=C3=ADguez_Ibeas?= <dibeas@ieee.org>
Date: Sun, 8 Feb 2015 21:18:20 -0500
Raw View
--001a11c16a905761ee050e9e6209
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

"On the other hand, catching a base class by value gives the catch block
its own modifiable copy. This might not be very useful, and might seldom
reflect a strong intent of the programmer, but there=E2=80=99s no other way=
 to
achieve it than to initialize the parameter by value."

Well, surely there is one that strongly shows the intent:

catch (myexcept const & r) {
   myexcept copy( r );
=E2=80=A6

But that is, in my opinion, beyond the point.  C++ has values, pointers and
two types of references; programmers need to be aware of them for building
any non-trivial piece of code.  Slicing is not a problem limited to
exceptions, and exception throwing/catching is not where slicing is more
common.  This is completely out of the context of exceptions, in this niche
you can always give sane simple rules: throw by value, catch by reference
[not sure if Microsoft's COM still recommends throwing by pointer=E2=80=A6 =
but you
should be aware of the idioms for your target platform].

I am not fond of proposals that aim to simplify part of the language in
only a small use case. That creates a leaking abstraction, consider that
this was allowed, then the compiler would warn/error out when the catch
clause but not on the body, leaving this with the same error:

catch (myexcept const & ref) {
    processException(ref);        // void processException(myexcept ex)

On Sun, Feb 8, 2015 at 8:52 PM, David Krauss <potswa@gmail.com> wrote:

>
> On 2015=E2=80=9302=E2=80=9309, at 9:36 AM, gmisocpp@gmail.com wrote:
>
> I think in my case the issue was that when I was learning C++ I was
> confused about pointers and references and values.
> i.e. If I threw a pointer was I throwing a copy of the object that I was
> pointing to, or just the pointer.
> Also since I equated references and pointers in my mind it then wasn't
> clear to me then if I threw something I had a reference to, was I actuall=
y
> throwing a pointer still and should I catch it with a pointer or referenc=
e
> to handle that.
> Add to that, if I catch by value, am I catching my original object thrown
> by value or a copy of it, or a copy of a copy. etc. and you can see why
> anything that could have stopped me getting into that mental mess might
> have been good!
>
> Hey that all strangely leads me off to a different idea:
> When we throw x, why can't we treat that as a move in some instances, lik=
e
> return does!?
>
>
> My answer to all this would be that 99% of users will only ever throw
> prvalue expressions of the form
>
>     throw exception_type{ simple, constants };
>
> =E2=80=A6 and although unsafe slicing may occur on catch-by-value, refere=
nces
> within the sliced base object will tend to refer only into the original
> derived exception, which is safely preserved.
>
> There are users coming from Java who try to put new everywhere, but
> that=E2=80=99s just uniformly wrong.
>
> Throwing expressions of non-class type is a bit silly, but deprecating
> that sort of thing smacks of playing thought-police.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--001a11c16a905761ee050e9e6209
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">&quot;<span style=3D"font-size:13px">On the other hand, ca=
tching a base class by value gives the catch block its own modifiable copy.=
 This might not be very useful, and might seldom reflect a strong intent of=
 the programmer, but there=E2=80=99s no other way to achieve it than to ini=
tialize the parameter by value.&quot;</span><div><span style=3D"font-size:1=
3px"><br></span></div><div><span style=3D"font-size:13px">Well, surely ther=
e is one that strongly shows the intent:</span></div><div><span style=3D"fo=
nt-size:13px"><br></span></div><div><span style=3D"font-size:13px">catch (m=
yexcept const &amp; r) {</span></div><div>=C2=A0 =C2=A0myexcept copy( r );<=
/div><div>=E2=80=A6</div><div><br></div><div>But that is, in my opinion, be=
yond the point.=C2=A0 C++ has values, pointers and two types of references;=
 programmers need to be aware of them for building any non-trivial piece of=
 code.=C2=A0 Slicing is not a problem limited to exceptions, and exception =
throwing/catching is not where slicing is more common.=C2=A0 This is comple=
tely out of the context of exceptions, in this niche you can always give sa=
ne simple rules: throw by value, catch by reference [not sure if Microsoft&=
#39;s COM still recommends throwing by pointer=E2=80=A6 but you should be a=
ware of the idioms for your target platform].</div><div><br></div><div>I am=
 not fond of proposals that aim to simplify part of the language in only a =
small use case. That creates a leaking abstraction, consider that this was =
allowed, then the compiler would warn/error out when the catch clause but n=
ot on the body, leaving this with the same error:</div><div><br></div><div>=
catch (myexcept const &amp; ref) {</div><div>=C2=A0 =C2=A0 processException=
(ref); =C2=A0 =C2=A0 =C2=A0 =C2=A0// void processException(myexcept ex)</di=
v></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Sun, F=
eb 8, 2015 at 8:52 PM, David Krauss <span dir=3D"ltr">&lt;<a href=3D"mailto=
:potswa@gmail.com" target=3D"_blank">potswa@gmail.com</a>&gt;</span> wrote:=
<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-lef=
t:1px #ccc solid;padding-left:1ex"><div style=3D"word-wrap:break-word"><spa=
n class=3D""><br><div><blockquote type=3D"cite"><div>On 2015=E2=80=9302=E2=
=80=9309, at 9:36 AM, <a href=3D"mailto:gmisocpp@gmail.com" target=3D"_blan=
k">gmisocpp@gmail.com</a> wrote:</div><br><div><div dir=3D"ltr">I think in =
my case=C2=A0the issue was that when I was learning C++=C2=A0I was confused=
 about pointers and references and values.<br><div>i.e. If I threw a pointe=
r=C2=A0was I throwing a copy of the object that I was pointing to, or just =
the pointer.</div><div>Also since I equated references and pointers in my m=
ind=C2=A0it then wasn&#39;t clear to me then=C2=A0if I threw something=C2=
=A0I had a=C2=A0reference to, was I actually throwing a pointer still and s=
hould I catch=C2=A0it with a pointer or reference to handle that.</div><div=
>Add to that, if I catch by value, am I catching my=C2=A0original object th=
rown by value or a copy of it, or a copy of=C2=A0a copy. etc. and you can s=
ee why anything that could have stopped me getting into that mental mess mi=
ght have been good!</div><div><br></div><div>Hey that all strangely leads m=
e off to a different idea:</div><div>When we throw x, why can&#39;t we trea=
t that as a move in some instances, like return does!?</div></div></div></b=
lockquote><br></div></span><div>My answer to all this would be that 99% of =
users will only ever throw prvalue expressions of the form</div><div><br></=
div><div><font face=3D"Courier">=C2=A0 =C2=A0 throw exception_type{ simple,=
 constants };</font></div><div><br></div><div>=E2=80=A6 and although unsafe=
 slicing may occur on catch-by-value, references within the sliced base obj=
ect will tend to refer only into the original derived exception, which is s=
afely preserved.</div><div><br></div><div>There are users coming from Java =
who try to put <font face=3D"Courier">new</font> everywhere, but that=E2=80=
=99s just uniformly wrong.</div><div><br></div><div>Throwing expressions of=
 non-class type is a bit silly, but deprecating that sort of thing smacks o=
f playing thought-police.</div></div><div class=3D"HOEnZb"><div class=3D"h5=
">

<p></p>

-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11c16a905761ee050e9e6209--

.


Author: gmisocpp@gmail.com
Date: Mon, 9 Feb 2015 13:14:20 -0800 (PST)
Raw View
------=_Part_2583_887608778.1423516460548
Content-Type: multipart/alternative;
 boundary="----=_Part_2584_1619319784.1423516460549"

------=_Part_2584_1619319784.1423516460549
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Monday, February 9, 2015 at 3:18:22 PM UTC+13, David Rodr=C3=ADguez Ibea=
s=20
wrote:
>
> "On the other hand, catching a base class by value gives the catch block=
=20
> its own modifiable copy. This might not be very useful, and might seldom=
=20
> reflect a strong intent of the programmer, but there=E2=80=99s no other w=
ay to=20
> achieve it than to initialize the parameter by value."
>
> Well, surely there is one that strongly shows the intent:
>
> catch (myexcept const & r) {
>    myexcept copy( r );
> =E2=80=A6
>
> But that is, in my opinion, beyond the point.  C++ has values, pointers=
=20
> and two types of references; programmers need to be aware of them for=20
> building any non-trivial piece of code.  Slicing is not a problem limited=
=20
> to exceptions, and exception throwing/catching is not where slicing is mo=
re=20
> common.  This is completely out of the context of exceptions, in this nic=
he=20
> you can always give sane simple rules: throw by value, catch by reference=
=20
> [not sure if Microsoft's COM still recommends throwing by pointer=E2=80=
=A6 but you=20
> should be aware of the idioms for your target platform].
>
> I am not fond of proposals that aim to simplify part of the language in=
=20
> only a small use case. That creates a leaking abstraction, consider that=
=20
> this was allowed, then the compiler would warn/error out when the catch=
=20
> clause but not on the body, leaving this with the same error:
>

Understood. That's why I said this earlier:

"So more generally then, In the earlier example:

    my_derived d;
    my_base b;
    b =3D d; // Where useful? Happens without intention more often than not=
?
"
=20
and posed the question is slicing really a problem anyway?
It seems there are people who think it isn't and they are probably right.
But if it is a problem I was wondering if there was value in a warning by=
=20
default about slicing and for the above kind of assignment.
And perhaps requiring a b =3D slice_cast<b>(d) instead or something to avoi=
d=20
the warning.

My thoughts were that catching by reference would be one step on the=20
road to avoiding accidental slicing.
But I am suspecting now though that "fixing" slicing it is not possible and=
=20
not worth the effort even if it were as it's not really a problem anyway. I=
=20
am interested in what other people think on that though.

catch (myexcept const & ref) {
>     processException(ref);        // void processException(myexcept ex)
>
> On Sun, Feb 8, 2015 at 8:52 PM, David Krauss <pot...@gmail.com=20
> <javascript:>> wrote:
>
>>
>> On 2015=E2=80=9302=E2=80=9309, at 9:36 AM, gmis...@gmail.com <javascript=
:> wrote:
>>
>> I think in my case the issue was that when I was learning C++ I was=20
>> confused about pointers and references and values.
>> i.e. If I threw a pointer was I throwing a copy of the object that I was=
=20
>> pointing to, or just the pointer.
>> Also since I equated references and pointers in my mind it then wasn't=
=20
>> clear to me then if I threw something I had a reference to, was I actual=
ly=20
>> throwing a pointer still and should I catch it with a pointer or referen=
ce=20
>> to handle that.
>> Add to that, if I catch by value, am I catching my original object throw=
n=20
>> by value or a copy of it, or a copy of a copy. etc. and you can see why=
=20
>> anything that could have stopped me getting into that mental mess might=
=20
>> have been good!
>>
>> Hey that all strangely leads me off to a different idea:
>> When we throw x, why can't we treat that as a move in some instances,=20
>> like return does!?
>>
>>
>> My answer to all this would be that 99% of users will only ever throw=20
>> prvalue expressions of the form
>>
>>     throw exception_type{ simple, constants };
>>
>> =E2=80=A6 and although unsafe slicing may occur on catch-by-value, refer=
ences=20
>> within the sliced base object will tend to refer only into the original=
=20
>> derived exception, which is safely preserved.
>>
>> There are users coming from Java who try to put new everywhere, but=20
>> that=E2=80=99s just uniformly wrong.
>>
>> Throwing expressions of non-class type is a bit silly, but deprecating=
=20
>> that sort of thing smacks of playing thought-police.
>>
>> --=20
>>
>> ---=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> Visit this group at=20
>> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>
>
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_2584_1619319784.1423516460549
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Monday, February 9, 2015 at 3:18:22 PM UTC+13, =
David Rodr=C3=ADguez Ibeas wrote:<blockquote class=3D"gmail_quote" style=3D=
"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, =
204, 204); border-left-width: 1px; border-left-style: solid;"><div dir=3D"l=
tr">"<span style=3D"font-size: 13px;">On the other hand, catching a base cl=
ass by value gives the catch block its own modifiable copy. This might not =
be very useful, and might seldom reflect a strong intent of the programmer,=
 but there=E2=80=99s no other way to achieve it than to initialize the para=
meter by value."</span><div><span style=3D"font-size: 13px;"><br></span></d=
iv><div><span style=3D"font-size: 13px;">Well, surely there is one that str=
ongly shows the intent:</span></div><div><span style=3D"font-size: 13px;"><=
br></span></div><div><span style=3D"font-size: 13px;">catch (myexcept const=
 &amp; r) {</span></div><div>&nbsp; &nbsp;myexcept copy( r );</div><div>=E2=
=80=A6</div><div><br></div><div>But that is, in my opinion, beyond the poin=
t.&nbsp; C++ has values, pointers and two types of references; programmers =
need to be aware of them for building any non-trivial piece of code.&nbsp; =
Slicing is not a problem limited to exceptions, and exception throwing/catc=
hing is not where slicing is more common.&nbsp; This is completely out of t=
he context of exceptions, in this niche you can always give sane simple rul=
es: throw by value, catch by reference [not sure if Microsoft's COM still r=
ecommends throwing by pointer=E2=80=A6 but you should be aware of the idiom=
s for your target platform].</div><div><br></div><div>I am not fond of prop=
osals that aim to simplify part of the language in only a small use case. T=
hat creates a leaking abstraction, consider that this was allowed, then the=
 compiler would warn/error out when the catch clause but not on the body, l=
eaving this with the same error:</div></div></blockquote><div><br></div><di=
v>Understood. That's why I said this earlier:</div><div><br></div><div><div=
>"So more generally then, In the earlier example:</div><div><br></div><div>=
<div>&nbsp;&nbsp;&nbsp; my_derived d;<br>&nbsp;&nbsp;&nbsp; my_base b;<br>&=
nbsp;&nbsp;&nbsp; b =3D d; // Where useful?&nbsp;Happens without intention =
more often&nbsp;than not?</div></div></div><div>"</div><div>&nbsp;</div><di=
v><div>and posed the&nbsp;question is slicing really a problem anyway?</div=
><div>It seems there are people who think it isn't and they are probably ri=
ght.</div>But if it is a problem I was wondering if there was value in&nbsp=
;a warning by default about slicing&nbsp;and for&nbsp;the above&nbsp;kind o=
f&nbsp;assignment.</div><div>And perhaps requiring a b =3D slice_cast&lt;b&=
gt;(d) instead or something to avoid the warning.</div><div><br></div><div>=
My thoughts were that catching by reference would be one&nbsp;step on the r=
oad&nbsp;to avoiding accidental slicing.</div><div>But I am suspecting&nbsp=
;now though that&nbsp;"fixing" slicing it is not possible&nbsp;and not wort=
h the effort even if it were as it's not really a problem anyway. I am inte=
rested in what other people think on that though.</div><div><br></div><bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-le=
ft: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; bor=
der-left-style: solid;"><div dir=3D"ltr"><div>catch (myexcept const &amp; r=
ef) {</div><div>&nbsp; &nbsp; processException(ref); &nbsp; &nbsp; &nbsp; &=
nbsp;// void processException(myexcept ex)</div></div><div><br><div class=
=3D"gmail_quote">On Sun, Feb 8, 2015 at 8:52 PM, David Krauss <span dir=3D"=
ltr">&lt;<a onmousedown=3D"this.href=3D'javascript:';return true;" onclick=
=3D"this.href=3D'javascript:';return true;" href=3D"javascript:" target=3D"=
_blank" rel=3D"nofollow" gdf-obfuscated-mailto=3D"BQcJ8S-wbaoJ">pot...@gmai=
l.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"m=
argin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 20=
4, 204); border-left-width: 1px; border-left-style: solid;"><div style=3D"-=
ms-word-wrap: break-word;"><span><br><div><blockquote type=3D"cite"><div>On=
 2015=E2=80=9302=E2=80=9309, at 9:36 AM, <a onmousedown=3D"this.href=3D'jav=
ascript:';return true;" onclick=3D"this.href=3D'javascript:';return true;" =
href=3D"javascript:" target=3D"_blank" rel=3D"nofollow" gdf-obfuscated-mail=
to=3D"BQcJ8S-wbaoJ">gmis...@gmail.com</a> wrote:</div><br><div><div dir=3D"=
ltr">I think in my case&nbsp;the issue was that when I was learning C++&nbs=
p;I was confused about pointers and references and values.<br><div>i.e. If =
I threw a pointer&nbsp;was I throwing a copy of the object that I was point=
ing to, or just the pointer.</div><div>Also since I equated references and =
pointers in my mind&nbsp;it then wasn't clear to me then&nbsp;if I threw so=
mething&nbsp;I had a&nbsp;reference to, was I actually throwing a pointer s=
till and should I catch&nbsp;it with a pointer or reference to handle that.=
</div><div>Add to that, if I catch by value, am I catching my&nbsp;original=
 object thrown by value or a copy of it, or a copy of&nbsp;a copy. etc. and=
 you can see why anything that could have stopped me getting into that ment=
al mess might have been good!</div><div><br></div><div>Hey that all strange=
ly leads me off to a different idea:</div><div>When we throw x, why can't w=
e treat that as a move in some instances, like return does!?</div></div></d=
iv></blockquote><br></div></span><div>My answer to all this would be that 9=
9% of users will only ever throw prvalue expressions of the form</div><div>=
<br></div><div><font face=3D"Courier">&nbsp; &nbsp; throw exception_type{ s=
imple, constants };</font></div><div><br></div><div>=E2=80=A6 and although =
unsafe slicing may occur on catch-by-value, references within the sliced ba=
se object will tend to refer only into the original derived exception, whic=
h is safely preserved.</div><div><br></div><div>There are users coming from=
 Java who try to put <font face=3D"Courier">new</font> everywhere, but that=
=E2=80=99s just uniformly wrong.</div><div><br></div><div>Throwing expressi=
ons of non-class type is a bit silly, but deprecating that sort of thing sm=
acks of playing thought-police.</div></div><div><div>

<p></p>

-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a onmousedown=3D"this.href=3D'javascript:';return true;" onclick=
=3D"this.href=3D'javascript:';return true;" href=3D"javascript:" target=3D"=
_blank" rel=3D"nofollow" gdf-obfuscated-mailto=3D"BQcJ8S-wbaoJ">std-proposa=
l...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a onmousedown=3D"this.href=3D'javascr=
ipt:';return true;" onclick=3D"this.href=3D'javascript:';return true;" href=
=3D"javascript:" target=3D"_blank" rel=3D"nofollow" gdf-obfuscated-mailto=
=3D"BQcJ8S-wbaoJ">std-pr...@isocpp.org</a>.<br>
Visit this group at <a onmousedown=3D"this.href=3D'http://groups.google.com=
/a/isocpp.org/group/std-proposals/';return true;" onclick=3D"this.href=3D'h=
ttp://groups.google.com/a/isocpp.org/group/std-proposals/';return true;" hr=
ef=3D"http://groups.google.com/a/isocpp.org/group/std-proposals/" target=3D=
"_blank" rel=3D"nofollow">http://groups.google.com/a/<wbr>isocpp.org/group/=
std-<wbr>proposals/</a>.<br>
</div></div></blockquote></div><br></div>
</blockquote></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2584_1619319784.1423516460549--
------=_Part_2583_887608778.1423516460548--

.


Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Mon, 9 Feb 2015 15:29:05 -0800 (PST)
Raw View
------=_Part_29_803476715.1423524545068
Content-Type: multipart/alternative;
 boundary="----=_Part_30_655976669.1423524545068"

------=_Part_30_655976669.1423524545068
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Sunday, February 8, 2015 at 5:36:48 PM UTC-8, gmis...@gmail.com wrote:
>
> On Monday, February 9, 2015 at 1:28:33 PM UTC+13, David Krauss wrote:
>>
>>
>> Perhaps it=E2=80=99s hard to remember because it doesn=E2=80=99t make mu=
ch of a=20
>> difference either way. There=E2=80=99s no such thing as throwing by refe=
rence, at=20
>> all. You can get a little extra efficiency by using std::move when=20
>> throwing, but there=E2=80=99s not really much point. [...]
>>
>
> Hey that all strangely leads me off to a different idea:
> When we throw x, why can't we treat that as a move in some instances, lik=
e=20
> return does!?
>

There are two things going on here:
- "return x;" and "throw x;", where x is a local variable, will both treat=
=20
x as an rvalue rather than an lvalue. (This is specified in 12.8 /32 of=20
draft standard N4296.)
- Copy/move elision. "return x;" and "throw x;" are both permitted to elide=
=20
the copy/move construction. (These are specified in 12.8 /31.1 and /31.2=20
respectively.)

In other words, "throw x;" will neither copy nor move in the usual case;=20
but if you somehow manage to disable copy elision in your compiler, it will=
=20
still move. It is not *permitted* to make a copy, unless there are=20
extenuating circumstances (such as the move constructor having been=20
deleted).

Writing "throw std::move(x);" will inhibit move elision, so don't do that.

=E2=80=93Arthur

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_30_655976669.1423524545068
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Sunday, February 8, 2015 at 5:36:48 PM UTC-8, gmis...@g=
mail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr=
">On Monday, February 9, 2015 at 1:28:33 PM UTC+13, David Krauss wrote:<blo=
ckquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-lef=
t:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-=
style:solid"><div><br><div>Perhaps it=E2=80=99s hard to remember because it=
 doesn=E2=80=99t make much of a difference either way. There=E2=80=99s no s=
uch thing as throwing by reference, at all. You can get a little extra effi=
ciency by using <font face=3D"Courier">std::move</font> when throwing, but =
there=E2=80=99s not really much point. [...]</div></div></blockquote><div><=
br></div><div>Hey that all strangely leads me off to a different idea:</div=
><div>When we throw x, why can't we treat that as a move in some instances,=
 like return does!?</div></div></blockquote><div><br></div><div>There are t=
wo things going on here:</div><div>- "return x;" and "throw x;", where x is=
 a local variable, will both treat x as an rvalue rather than an lvalue. (T=
his is specified in 12.8 /32 of draft standard N4296.)</div><div>- Copy/mov=
e elision. "return x;" and "throw x;" are both permitted to elide the copy/=
move construction. (These are specified in 12.8 /31.1 and /31.2 respectivel=
y.)</div><div><br></div><div>In other words, "throw x;" will neither copy n=
or move in the usual case; but if you somehow manage to disable copy elisio=
n in your compiler, it will still move. It is not *permitted* to make a cop=
y, unless there are extenuating circumstances (such as the move constructor=
 having been deleted).</div><div><br></div><div>Writing "throw std::move(x)=
;" will inhibit move elision, so don't do that.</div><div><br></div><div>=
=E2=80=93Arthur</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_30_655976669.1423524545068--
------=_Part_29_803476715.1423524545068--

.


Author: David Krauss <potswa@gmail.com>
Date: Tue, 10 Feb 2015 08:00:41 +0800
Raw View
--Apple-Mail=_999580B2-BE70-4EE6-8C07-C9E3990EA1C4
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9302=E2=80=9310, at 7:29 AM, Arthur O'Dwyer <arthur.j.odwye=
r@gmail.com> wrote:
>=20
> Writing "throw std::move(x);" will inhibit move elision, so don't do that=
..

=E2=80=A6 unless elision wouldn=E2=80=99t apply anyway because it=E2=80=99s=
 a member or nonlocal.

Seriously, though, when is the last time you constructed an exception objec=
t in a different statement from the throw expression? This is of some inter=
est to me, because I have a planned proposal about exception synchronizatio=
n, and it=E2=80=99s easier to implement if exceptions can order themselves =
by the time of construction and not the time of throw.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_999580B2-BE70-4EE6-8C07-C9E3990EA1C4
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9302=
=E2=80=9310, at 7:29 AM, Arthur O'Dwyer &lt;<a href=3D"mailto:arthur.j.odwy=
er@gmail.com" class=3D"">arthur.j.odwyer@gmail.com</a>&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><div class=3D""><div style=3D"font-fami=
ly: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; f=
ont-weight: normal; letter-spacing: normal; line-height: normal; orphans: a=
uto; text-align: start; text-indent: 0px; text-transform: none; white-space=
: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"=
 class=3D"">Writing "throw std::move(x);" will inhibit move elision, so don=
't do that.</div></div></blockquote></div><br class=3D""><div class=3D"">=
=E2=80=A6 unless elision wouldn=E2=80=99t apply anyway because it=E2=80=99s=
 a member or nonlocal.</div><div class=3D""><br class=3D""></div><div class=
=3D"">Seriously, though, when is the last time you constructed an exception=
 object in a different statement from the throw expression? This is of some=
 interest to me, because I have a planned proposal about exception synchron=
ization, and it=E2=80=99s easier to implement if exceptions can order thems=
elves by the time of construction and not the time of throw.</div></body></=
html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_999580B2-BE70-4EE6-8C07-C9E3990EA1C4--

.


Author: "Arthur O'Dwyer" <arthur.j.odwyer@gmail.com>
Date: Mon, 9 Feb 2015 16:14:34 -0800
Raw View
--f46d0444e983809f39050eb0c5c4
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Mon, Feb 9, 2015 at 4:00 PM, David Krauss <potswa@gmail.com> wrote:

> On 2015=E2=80=9302=E2=80=9310, at 7:29 AM, Arthur O'Dwyer <arthur.j.odwye=
r@gmail.com>
> wrote:
>
> Writing "throw std::move(x);" will inhibit move elision, so don't do that=
..
>
>
> =E2=80=A6 unless elision wouldn=E2=80=99t apply anyway because it=E2=80=
=99s a member or nonlocal.
>

Right.


> Seriously, though, when is the last time you constructed an exception
> object in a different statement from the throw expression? This is of som=
e
> interest to me, because I have a planned proposal about exception
> synchronization, and it=E2=80=99s easier to implement if exceptions can o=
rder
> themselves by the time of construction and not the time of throw.
>

Not sure if this is aimed at me, or the OP, or anyone in general; but for
what it's worth, my answer is "never". I would agree that the expected
use-case for throw/catch is

    throw MyExceptionClass(args...);

    catch (const MyExceptionClass&) ...

The only thing I've done different from that in my life is

    throw "string literals are cheaper than std::exceptions";

and then catch (const char *).

=E2=80=93Arthur

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--f46d0444e983809f39050eb0c5c4
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Mon, Feb 9, 2015 at 4:00 PM, David Krauss <span dir=3D"=
ltr">&lt;<a href=3D"mailto:potswa@gmail.com" target=3D"_blank">potswa@gmail=
..com</a>&gt;</span> wrote:<br><div class=3D"gmail_extra"><div class=3D"gmai=
l_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;borde=
r-left:1px #ccc solid;padding-left:1ex"><div style=3D"word-wrap:break-word"=
><div><blockquote type=3D"cite"><div>On 2015=E2=80=9302=E2=80=9310, at 7:29=
 AM, Arthur O&#39;Dwyer &lt;<a href=3D"mailto:arthur.j.odwyer@gmail.com" ta=
rget=3D"_blank">arthur.j.odwyer@gmail.com</a>&gt; wrote:</div><br><div><div=
 style=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-varia=
nt:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-=
align:start;text-indent:0px;text-transform:none;white-space:normal;word-spa=
cing:0px">Writing &quot;throw std::move(x);&quot; will inhibit move elision=
, so don&#39;t do that.</div></div></blockquote></div><br><div>=E2=80=A6 un=
less elision wouldn=E2=80=99t apply anyway because it=E2=80=99s a member or=
 nonlocal.</div></div></blockquote><div><br></div><div>Right.</div><div>=C2=
=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;borde=
r-left:1px #ccc solid;padding-left:1ex"><div style=3D"word-wrap:break-word"=
><div>Seriously, though, when is the last time you constructed an exception=
 object in a different statement from the throw expression? This is of some=
 interest to me, because I have a planned proposal about exception synchron=
ization, and it=E2=80=99s easier to implement if exceptions can order thems=
elves by the time of construction and not the time of throw.</div></div></b=
lockquote><div><br></div><div>Not sure if this is aimed at me, or the OP, o=
r anyone in general; but for what it&#39;s worth, my answer is &quot;never&=
quot;. I would agree that the expected use-case for throw/catch is</div><di=
v><br></div><div>=C2=A0 =C2=A0 throw MyExceptionClass(args...);</div><div><=
br></div><div>=C2=A0 =C2=A0 catch (const MyExceptionClass&amp;) ...</div><d=
iv>=C2=A0</div><div>The only thing I&#39;ve done different from that in my =
life is</div><div><br></div><div>=C2=A0 =C2=A0 throw &quot;string literals =
are cheaper than std::exceptions&quot;;</div><div><br></div><div>and then c=
atch (const char *).</div><div><br></div><div>=E2=80=93Arthur</div></div></=
div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--f46d0444e983809f39050eb0c5c4--

.