Topic: Error Handling
Author: Olanrewaju Adetula <jsphadetula@gmail.com>
Date: Sun, 26 Apr 2015 08:35:29 -0700 (PDT)
Raw View
------=_Part_111_842461450.1430062529402
Content-Type: multipart/alternative;
boundary="----=_Part_112_889905479.1430062529402"
------=_Part_112_889905479.1430062529402
Content-Type: text/plain; charset=UTF-8
Can the C++ standards committee add support for return statements in
constructors, this automatically change the return type of such constructor
to a specially defined optional type which can be checked for errors, the
returned object is added to the returned optional type which can then be
checked by the calling code for errors. When no error is encountered, a
standard no error state is encoded by the compiler into the optional type.
Return value in a constructor also signals incomplete initialization,
thereby informing the compiler to do any necessary cleanup to maintain the
RAII principle already in place. Such return values should also be a type
that does not throw or a type predefined by the standard
Constructors with no return statement(s) in their body keep returning
object of constructor's type as it's currently being done and can therefore
continue to throw exceptions.
class MyClass{
public:
MyClass(T tvalue){
if( !isValid(tvalue) ){
return ErrorCases::InvalidValue; //assumed error case
}
}
};
auto myObj = new MyClass(tvalue); typeof myObj is a special optional type
encapsulating the error state
if( !myObj ){
DoErrorProcessing();
}
else{
ContinueNormalProcessing();
}
--
---
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/.
------=_Part_112_889905479.1430062529402
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Can the C++ standards committee add support for return sta=
tements in constructors, this automatically change the return type of such =
constructor to a specially defined optional type which can be checked for e=
rrors, the returned object is added to the returned optional type which can=
then be checked by the calling code for errors. When no error is encounter=
ed, a standard no error state is encoded by the compiler into the optional =
type. <br>Return value in a constructor also signals incomplete initializat=
ion, thereby informing the compiler to do any necessary cleanup to maintain=
the RAII principle already in place. Such return values should also be a t=
ype that does not throw or a type predefined by the standard<br>Constructor=
s with no return statement(s) in their body keep returning object of constr=
uctor's type as it's currently being done and can therefore continue to thr=
ow exceptions.<br><br><div class=3D"prettyprint" style=3D"background-color:=
rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid;=
border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><di=
v class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-=
prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyCl=
ass</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">public</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><sp=
an style=3D"color: #606;" class=3D"styled-by-prettify">MyClass</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">T tvalue</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">){</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">if</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">!</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">isValid</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">tvalue</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">){</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br> &n=
bsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">retur=
n</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #606;" class=3D"styled-by-prettify">ErrorCases</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">InvalidValue</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #80=
0;" class=3D"styled-by-prettify">//assumed error case</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> myObj </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">new</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyClass<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">tvalue</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typeof</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> myObj </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">is</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> a special optional type encapsulating the error state<b=
r></span><span style=3D"color: #008;" class=3D"styled-by-prettify">if</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">!</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">myObj </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">){</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br> </span><span style=3D"color: #606;" class=3D=
"styled-by-prettify">DoErrorProcessing</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
else</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> </sp=
an><span style=3D"color: #606;" class=3D"styled-by-prettify">ContinueNormal=
Processing</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></cod=
e></div><br><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" 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_112_889905479.1430062529402--
------=_Part_111_842461450.1430062529402--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 26 Apr 2015 18:16:01 +0200
Raw View
This is a multi-part message in MIME format.
--------------020803090108080604030300
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 26/04/15 17:35, Olanrewaju Adetula a =C3=A9crit :
> Can the C++ standards committee add support for return statements in=20
> constructors, this automatically change the return type of such=20
> constructor to a specially defined optional type which can be checked=20
> for errors, the returned object is added to the returned optional type=20
> which can then be checked by the calling code for errors. When no=20
> error is encountered, a standard no error state is encoded by the=20
> compiler into the optional type.
I don't see how the compiler will know if the constructor returns or not=20
an error code without looking inside the code.
The question is, why do you want this behavior? Why you don't want to=20
use exceptions?
> Return value in a constructor also signals incomplete initialization,=20
> thereby informing the compiler to do any necessary cleanup to maintain=20
> the RAII principle already in place. Such return values should also be=20
> a type that does not throw or a type predefined by the standard
I don't understand how you can get an error code and at the same time do=20
as if an exception were thrown.
> Constructors with no return statement(s) in their body keep returning=20
> object of constructor's type as it's currently being done and can=20
> therefore continue to throw exceptions.
>
> |
> classMyClass{
> public:
> MyClass(T tvalue){
> if(!isValid(tvalue)){
> returnErrorCases::InvalidValue;//assumed error case
> }
> }
> };
>
> automyObj =3DnewMyClass(tvalue);typeofmyObj isa special optional type=20
> encapsulating the error state
> if(!myObj ){
> DoErrorProcessing();
> }
> else{
> ContinueNormalProcessing();
> }
> |
>
With perfect forwarding, you can get sommeting like that in c++14,=20
without modifying the language. You can define your own New function
if MyClass (T) constructor throws,
|
automyObj =3DNew<MyClass>(tvalue);
//decltypemyObj could be a smart pointer storing also the error code,=20
something like the proposed class expected.
if(!myObj ){
DoErrorProcessing(|myObj.error()|);
}
else{
ContinueNormalProcessing(||myObj.get()||);
}
|
Vicente
--=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/.
--------------020803090108080604030300
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body text=3D"#000000" bgcolor=3D"#FFFFFF">
<div class=3D"moz-cite-prefix">Le 26/04/15 17:35, Olanrewaju Adetula a
=C3=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:fee1b8e1-3bdd-4974-8c28-51dbaaa24c5d@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">Can the C++ standards committee add support for
return statements in constructors, this automatically change the
return type of such constructor to a specially defined optional
type which can be checked for errors, the returned object is
added to the returned optional type which can then be checked by
the calling code for errors. When no error is encountered, a
standard no error state is encoded by the compiler into the
optional type. <br>
</div>
</blockquote>
I don't see how the compiler will know if the constructor returns or
not an error code without looking inside the code.<br>
<br>
The question is, why do you want this behavior? Why you don't want
to use exceptions?<br>
<br>
<blockquote
cite=3D"mid:fee1b8e1-3bdd-4974-8c28-51dbaaa24c5d@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">Return value in a constructor also signals
incomplete initialization, thereby informing the compiler to do
any necessary cleanup to maintain the RAII principle already in
place. Such return values should also be a type that does not
throw or a type predefined by the standard<br>
</div>
</blockquote>
<br>
I don't understand how you can get an error code and at the same
time do as if an exception were thrown. <br>
<blockquote
cite=3D"mid:fee1b8e1-3bdd-4974-8c28-51dbaaa24c5d@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">Constructors with no return statement(s) in their
body keep returning object of constructor's type as it's
currently being done and can therefore continue to throw
exceptions.<br>
<br>
<div class=3D"prettyprint" style=3D"background-color: rgb(250, 250,
250); border-color: rgb(187, 187, 187); border-style: solid;
border-width: 1px; word-wrap: break-word;"><code
class=3D"prettyprint">
<div class=3D"subprettyprint"><span style=3D"color: #008;"
class=3D"styled-by-prettify">class</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">MyClass=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">public</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">:</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 =C2=A0 </span><span style=3D"color: #606;"
class=3D"styled-by-prettify">MyClass</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify">T tvalu=
e</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">){</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">if</span><span style=3D"color:
#660;" class=3D"styled-by-prettify">(</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">!</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify">isValid=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify">tvalue<=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">)</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">){</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #0=
08;"
class=3D"styled-by-prettify">return</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">ErrorCa=
ses</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span
style=3D"color: #606;" class=3D"styled-by-prettify">Invalid=
Value</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">;</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #800;" class=3D"styled-by-prettify">//assum=
ed
error case</span><span style=3D"color: #000;"
class=3D"styled-by-prettify"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #660;"
class=3D"styled-by-prettify">}</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
=C2=A0 =C2=A0 </span><span style=3D"color: #660;"
class=3D"styled-by-prettify">}</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">};</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
<br>
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">auto</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> myObj =
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #008;" class=3D"styled-by-prettify">new</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">MyClass=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify">tvalue<=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">);</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #008;" class=3D"styled-by-prettify">typeof<=
/span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> myObj =
</span><span
style=3D"color: #008;" class=3D"styled-by-prettify">is</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"> a
special optional type encapsulating the error state<br>
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">if</span><span style=3D"color:
#660;" class=3D"styled-by-prettify">(</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">!</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify">myObj <=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">){</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 </span><span style=3D"color: #606;"
class=3D"styled-by-prettify">DoErrorProcessing</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">();</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">}</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">else</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 </span><span style=3D"color: #606;"
class=3D"styled-by-prettify">ContinueNormalProcessing</span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">();</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">}</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
</span></div>
</code></div>
<br>
</div>
</blockquote>
With perfect forwarding, you can get sommeting like that in c++14,
without modifying the language. You can define your own New function<br=
>
<br>
if MyClass (T) constructor throws,<br>
<br>
<code class=3D"prettyprint">
<div class=3D"subprettyprint"><span style=3D"color: #000;"
class=3D"styled-by-prettify"></span><span style=3D"color: #008;"
class=3D"styled-by-prettify">auto</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"> myObj </span><span
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><sp=
an
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
style=3D"color: #000;" class=3D"styled-by-prettify">New<</span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">MyClass</span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">>(</span><=
span
style=3D"color: #000;" class=3D"styled-by-prettify">tvalue</span>=
<span
style=3D"color: #660;" class=3D"styled-by-prettify">);</span><spa=
n
style=3D"color: #000;" class=3D"styled-by-prettify"> <br>
//decltype</span><span style=3D"color: #000;"
class=3D"styled-by-prettify"> myObj could be a smart pointer
storing also the error code</span><span style=3D"color: #000;"
class=3D"styled-by-prettify">, something like the proposed class
expected.<br>
<br>
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">if=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
style=3D"color: #660;" class=3D"styled-by-prettify">!</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">myObj </span>=
<span
style=3D"color: #660;" class=3D"styled-by-prettify">){</span><spa=
n
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 </span><span style=3D"color: #606;"
class=3D"styled-by-prettify">DoErrorProcessing</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><code
class=3D"prettyprint"><span style=3D"color: #660;"
class=3D"styled-by-prettify"></span><span style=3D"color:
#000;" class=3D"styled-by-prettify">myObj.error()</span></cod=
e>);</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">}<=
/span><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">el=
se</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 </span><span style=3D"color: #606;"
class=3D"styled-by-prettify">ContinueNormalProcessing</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><code
class=3D"prettyprint"><span style=3D"color: #660;"
class=3D"styled-by-prettify"></span><span style=3D"color:
#660;" class=3D"styled-by-prettify"><code
class=3D"prettyprint"><span style=3D"color: #660;"
class=3D"styled-by-prettify"></span><span style=3D"color:
#000;" class=3D"styled-by-prettify">myObj.get()</span></c=
ode></span></code>);</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">}<=
/span><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
</span></div>
</code><br>
Vicente<br>
</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" 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 />
--------------020803090108080604030300--
.
Author: Olanrewaju Adetula <jsphadetula@gmail.com>
Date: Sun, 26 Apr 2015 17:39:37 +0100
Raw View
--f46d043be270729be90514a3467d
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
The question is, why do you want this behavior? Why you don't want to use
exceptions?
Yes, just thinking there should be a way to construct an object by
returning error state as part of object creation process while still
retaining RAII principle
On Apr 26, 2015 5:16 PM, "Vicente J. Botet Escriba" <
vicente.botet@wanadoo.fr> wrote:
> Le 26/04/15 17:35, Olanrewaju Adetula a =C3=A9crit :
>
> Can the C++ standards committee add support for return statements in
> constructors, this automatically change the return type of such construct=
or
> to a specially defined optional type which can be checked for errors, the
> returned object is added to the returned optional type which can then be
> checked by the calling code for errors. When no error is encountered, a
> standard no error state is encoded by the compiler into the optional type=
..
>
> I don't see how the compiler will know if the constructor returns or not
> an error code without looking inside the code.
>
> The question is, why do you want this behavior? Why you don't want to use
> exceptions?
>
> Return value in a constructor also signals incomplete initialization,
> thereby informing the compiler to do any necessary cleanup to maintain th=
e
> RAII principle already in place. Such return values should also be a type
> that does not throw or a type predefined by the standard
>
>
> I don't understand how you can get an error code and at the same time do
> as if an exception were thrown.
>
> Constructors with no return statement(s) in their body keep returning
> object of constructor's type as it's currently being done and can therefo=
re
> continue to throw exceptions.
>
> class MyClass{
> public:
> MyClass(T tvalue){
> if( !isValid(tvalue) ){
> return ErrorCases::InvalidValue; //assumed error case
> }
> }
> };
>
> auto myObj =3D new MyClass(tvalue); typeof myObj is a special optional ty=
pe
> encapsulating the error state
> if( !myObj ){
> DoErrorProcessing();
> }
> else{
> ContinueNormalProcessing();
> }
>
> With perfect forwarding, you can get sommeting like that in c++14,
> without modifying the language. You can define your own New function
>
> if MyClass (T) constructor throws,
>
> auto myObj =3D New<MyClass>(tvalue);
> //decltype myObj could be a smart pointer storing also the error code,
> something like the proposed class expected.
>
> if( !myObj ){
> DoErrorProcessing(myObj.error());
> }
> else{
> ContinueNormalProcessing(myObj.get());
> }
>
> Vicente
>
> --
>
> ---
> 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/.
--f46d043be270729be90514a3467d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">The question is, why do you want this behavior? Why you don&=
#39;t want to use exceptions?</p>
<p dir=3D"ltr">Yes, just thinking there should be a way to construct an obj=
ect by returning error state as part of object creation process while still=
retaining RAII principle</p>
<div class=3D"gmail_quote">On Apr 26, 2015 5:16 PM, "Vicente J. Botet =
Escriba" <<a href=3D"mailto:vicente.botet@wanadoo.fr">vicente.botet=
@wanadoo.fr</a>> wrote:<br type=3D"attribution"><blockquote class=3D"gma=
il_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-lef=
t:1ex">
=20
=20
=20
<div text=3D"#000000" bgcolor=3D"#FFFFFF">
<div>Le 26/04/15 17:35, Olanrewaju Adetula a
=C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">Can the C++ standards committee add support for
return statements in constructors, this automatically change the
return type of such constructor to a specially defined optional
type which can be checked for errors, the returned object is
added to the returned optional type which can then be checked by
the calling code for errors. When no error is encountered, a
standard no error state is encoded by the compiler into the
optional type. <br>
</div>
</blockquote>
I don't see how the compiler will know if the constructor returns o=
r
not an error code without looking inside the code.<br>
<br>
The question is, why do you want this behavior? Why you don't want
to use exceptions?<br>
<br>
<blockquote type=3D"cite">
<div dir=3D"ltr">Return value in a constructor also signals
incomplete initialization, thereby informing the compiler to do
any necessary cleanup to maintain the RAII principle already in
place. Such return values should also be a type that does not
throw or a type predefined by the standard<br>
</div>
</blockquote>
<br>
I don't understand how you can get an error code and at the same
time do as if an exception were thrown. <br>
<blockquote type=3D"cite">
<div dir=3D"ltr">Constructors with no return statement(s) in their
body keep returning object of constructor's type as it's
currently being done and can therefore continue to throw
exceptions.<br>
<br>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(18=
7,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><code>
<div><span style=3D"color:#008">class</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#606">MyClass</span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#008">public</span><span=
style=3D"color:#660">:</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#606">MyClass</sp=
an><span style=3D"color:#660">(</span><span style=3D"color:#000">T tvalue</=
span><span style=3D"color:#660">){</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">if</=
span><span style=3D"color:#660">(</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">!</span><span style=3D"color:#000">isValid</span=
><span style=3D"color:#660">(</span><span style=3D"color:#000">tvalue</span=
><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">){</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#00=
8">return</span><span style=3D"color:#000"> </span><span style=3D"color:#60=
6">ErrorCases</span><span style=3D"color:#660">::</span><span style=3D"colo=
r:#606">InvalidValue</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"> </span><span style=3D"color:#800">//assumed
error case</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#660">}</s=
pan><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><sp=
an style=3D"color:#000"><br>
</span><span style=3D"color:#660">};</span><span style=3D"col=
or:#000"><br>
<br>
</span><span style=3D"color:#008">auto</span><span style=3D"c=
olor:#000"> myObj </span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">new</span><span style=3D=
"color:#000"> </span><span style=3D"color:#606">MyClass</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">tvalue</span><span style=
=3D"color:#660">);</span><span style=3D"color:#000"> </span><span style=3D"=
color:#008">typeof</span><span style=3D"color:#000"> myObj </span><span sty=
le=3D"color:#008">is</span><span style=3D"color:#000"> a
special optional type encapsulating the error state<br>
</span><span style=3D"color:#008">if</span><span style=3D"col=
or:#660">(</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">!</span><span style=3D"color:#000">myObj </span><span style=3D"color:#6=
60">){</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#606">DoErrorProcessing<=
/span><span style=3D"color:#660">();</span><span style=3D"color:#000"><br>
</span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"><br>
</span><span style=3D"color:#008">else</span><span style=3D"c=
olor:#660">{</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#606">ContinueNormalProc=
essing</span><span style=3D"color:#660">();</span><span style=3D"color:#000=
"><br>
</span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"><br>
</span></div>
</code></div>
<br>
</div>
</blockquote>
With perfect forwarding, you can get sommeting like that in c++14,
without modifying the language. You can define your own New function<br=
>
<br>
if MyClass (T) constructor throws,<br>
<br>
<code>
<div><span style=3D"color:#000"></span><span style=3D"color:#008">aut=
o</span><span style=3D"color:#000"> myObj </span><span style=3D"color:#660"=
>=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#000">Ne=
w<</span><span style=3D"color:#606">MyClass</span><span style=3D"color:#=
660">>(</span><span style=3D"color:#000">tvalue</span><span style=3D"col=
or:#660">);</span><span style=3D"color:#000"> <br>
//decltype</span><span style=3D"color:#000"> myObj could be a sma=
rt pointer
storing also the error code</span><span style=3D"color:#000">, so=
mething like the proposed class
expected.<br>
<br>
</span><span style=3D"color:#008">if</span><span style=3D"color:#66=
0">(</span><span style=3D"color:#000"> </span><span style=3D"color:#660">!<=
/span><span style=3D"color:#000">myObj </span><span style=3D"color:#660">){=
</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#606">DoErrorProcessing</span>=
<span style=3D"color:#660">(</span><span style=3D"color:#660"><code><span s=
tyle=3D"color:#660"></span><span style=3D"color:#000">myObj.error()</span><=
/code>);</span><span style=3D"color:#000"><br>
</span><span style=3D"color:#660">}</span><span style=3D"color:#000=
"><br>
</span><span style=3D"color:#008">else</span><span style=3D"color:#=
660">{</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#606">ContinueNormalProcessing=
</span><span style=3D"color:#660">(</span><span style=3D"color:#660"><code>=
<span style=3D"color:#660"></span><span style=3D"color:#660"><code><span st=
yle=3D"color:#660"></span><span style=3D"color:#000">myObj.get()</span></co=
de></span></code>);</span><span style=3D"color:#000"><br>
</span><span style=3D"color:#660">}</span><span style=3D"color:#000=
"><br>
</span></div>
</code><br>
Vicente<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" 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>
</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" 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 />
--f46d043be270729be90514a3467d--
.
Author: David Krauss <potswa@gmail.com>
Date: Mon, 27 Apr 2015 00:47:13 +0800
Raw View
--Apple-Mail=_51E5F444-E1D5-498D-9C3E-A27A38524004
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2015=E2=80=9304=E2=80=9327, at 12:39 AM, Olanrewaju Adetula <jsphadetu=
la@gmail.com> wrote:
>=20
> The question is, why do you want this behavior? Why you don't want to use=
exceptions?
>=20
> Yes, just thinking there should be a way to construct an object by return=
ing error state as part of object creation process while still retaining RA=
II principle
>=20
You can use perfect forwarding to pass arguments to the constructor of std:=
:optional, inside a try/catch block. If you want, you could go further and =
save the exception with a std::exception_ptr, and return a discriminated un=
ion of that and the constructed class.
--=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=_51E5F444-E1D5-498D-9C3E-A27A38524004
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=9304=
=E2=80=9327, at 12:39 AM, Olanrewaju Adetula <<a href=3D"mailto:jsphadet=
ula@gmail.com" class=3D"">jsphadetula@gmail.com</a>> wrote:</div><br cla=
ss=3D"Apple-interchange-newline"><div class=3D""><p dir=3D"ltr" class=3D"">=
The question is, why do you want this behavior? Why you don't want to use e=
xceptions?</p><p dir=3D"ltr" class=3D"">Yes, just thinking there should be =
a way to construct an object by returning error state as part of object cre=
ation process while still retaining RAII principle</p></div></blockquote><d=
iv>You can use perfect forwarding to pass arguments to the constructor of <=
font face=3D"Courier" class=3D"">std::optional</font>, inside a <font face=
=3D"Courier" class=3D"">try</font>/<font face=3D"Courier" class=3D"">catch<=
/font> block. If you want, you could go further and save the exception with=
a <font face=3D"Courier" class=3D"">std::exception_ptr</font>, and return =
a discriminated union of that and the constructed class.</div></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" 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=_51E5F444-E1D5-498D-9C3E-A27A38524004--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 26 Apr 2015 19:50:44 +0300
Raw View
On 26 April 2015 at 19:47, David Krauss <potswa@gmail.com> wrote:
>
> On 2015=E2=80=9304=E2=80=9327, at 12:39 AM, Olanrewaju Adetula <jsphadetu=
la@gmail.com>
> wrote:
>
> The question is, why do you want this behavior? Why you don't want to use
> exceptions?
>
> Yes, just thinking there should be a way to construct an object by return=
ing
> error state as part of object creation process while still retaining RAII
> principle
>
> You can use perfect forwarding to pass arguments to the constructor of
> std::optional, inside a try/catch block. If you want, you could go furthe=
r
> and save the exception with a std::exception_ptr, and return a discrimina=
ted
> union of that and the constructed class.
Or use something along the lines of the proposed std::expected.
--=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/.
.
Author: Olanrewaju Adetula <jsphadetula@gmail.com>
Date: Sun, 26 Apr 2015 17:50:38 +0100
Raw View
--047d7bd6adced508160514a36db9
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
K, thanks
On Apr 26, 2015 5:47 PM, "David Krauss" <potswa@gmail.com> wrote:
>
> On 2015=E2=80=9304=E2=80=9327, at 12:39 AM, Olanrewaju Adetula <jsphadetu=
la@gmail.com>
> wrote:
>
> The question is, why do you want this behavior? Why you don't want to use
> exceptions?
>
> Yes, just thinking there should be a way to construct an object by
> returning error state as part of object creation process while still
> retaining RAII principle
>
> You can use perfect forwarding to pass arguments to the constructor of
> std::optional, inside a try/catch block. If you want, you could go
> further and save the exception with a std::exception_ptr, and return a
> discriminated union of that and the constructed class.
>
> --
>
> ---
> 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/.
--047d7bd6adced508160514a36db9
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">K, thanks </p>
<div class=3D"gmail_quote">On Apr 26, 2015 5:47 PM, "David Krauss"=
; <<a href=3D"mailto:potswa@gmail.com">potswa@gmail.com</a>> wrote:<b=
r type=3D"attribution"><blockquote class=3D"gmail_quote" style=3D"margin:0 =
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style=3D"word-wr=
ap:break-word"><br><div><blockquote type=3D"cite"><div>On 2015=E2=80=9304=
=E2=80=9327, at 12:39 AM, Olanrewaju Adetula <<a href=3D"mailto:jsphadet=
ula@gmail.com" target=3D"_blank">jsphadetula@gmail.com</a>> wrote:</div>=
<br><div><p dir=3D"ltr">The question is, why do you want this behavior? Why=
you don't want to use exceptions?</p><p dir=3D"ltr">Yes, just thinking=
there should be a way to construct an object by returning error state as p=
art of object creation process while still retaining RAII principle</p></di=
v></blockquote><div>You can use perfect forwarding to pass arguments to the=
constructor of <font face=3D"Courier">std::optional</font>, inside a <font=
face=3D"Courier">try</font>/<font face=3D"Courier">catch</font> block. If =
you want, you could go further and save the exception with a <font face=3D"=
Courier">std::exception_ptr</font>, and return a discriminated union of tha=
t and the constructed class.</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" 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>
</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" 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 />
--047d7bd6adced508160514a36db9--
.
Author: "dgutson ." <danielgutson@gmail.com>
Date: Sun, 26 Apr 2015 13:54:10 -0300
Raw View
--001a11334f148211ea0514a37a52
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
El 26/4/2015 13:50, "Ville Voutilainen" <ville.voutilainen@gmail.com>
escribi=C3=B3:
>
> On 26 April 2015 at 19:47, David Krauss <potswa@gmail.com> wrote:
> >
> > On 2015=E2=80=9304=E2=80=9327, at 12:39 AM, Olanrewaju Adetula <jsphade=
tula@gmail.com>
> > wrote:
> >
> > The question is, why do you want this behavior? Why you don't want to
use
> > exceptions?
> >
> > Yes, just thinking there should be a way to construct an object by
returning
> > error state as part of object creation process while still retaining
RAII
> > principle
> >
> > You can use perfect forwarding to pass arguments to the constructor of
> > std::optional, inside a try/catch block. If you want, you could go
further
> > and save the exception with a std::exception_ptr, and return a
discriminated
> > union of that and the constructed class.
>
>
> Or use something along the lines of the proposed std::expected.
This has been mentioned many times. Could you please point me to the latest
proposal and tell me its status?
>
> --
>
> ---
> 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/.
--001a11334f148211ea0514a37a52
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr"><br>
El 26/4/2015 13:50, "Ville Voutilainen" <<a href=3D"mailto:vil=
le.voutilainen@gmail.com">ville.voutilainen@gmail.com</a>> escribi=C3=B3=
:<br>
><br>
> On 26 April 2015 at 19:47, David Krauss <<a href=3D"mailto:potswa@g=
mail.com">potswa@gmail.com</a>> wrote:<br>
> ><br>
> > On 2015=E2=80=9304=E2=80=9327, at 12:39 AM, Olanrewaju Adetula &l=
t;<a href=3D"mailto:jsphadetula@gmail.com">jsphadetula@gmail.com</a>><br=
>
> > wrote:<br>
> ><br>
> > The question is, why do you want this behavior? Why you don't=
want to use<br>
> > exceptions?<br>
> ><br>
> > Yes, just thinking there should be a way to construct an object b=
y returning<br>
> > error state as part of object creation process while still retain=
ing RAII<br>
> > principle<br>
> ><br>
> > You can use perfect forwarding to pass arguments to the construct=
or of<br>
> > std::optional, inside a try/catch block. If you want, you could g=
o further<br>
> > and save the exception with a std::exception_ptr, and return a di=
scriminated<br>
> > union of that and the constructed class.<br>
><br>
><br>
> Or use something along the lines of the proposed std::expected.</p>
<p dir=3D"ltr">This has been mentioned many times. Could you please point m=
e to the latest proposal and tell me its status?</p>
<p dir=3D"ltr">><br>
> --<br>
><br>
> ---<br>
> You received this message because you are subscribed to the Google Gro=
ups "ISO C++ Standard - Future Proposals" group.<br>
> To unsubscribe from this group and stop receiving emails from it, send=
an email to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-=
proposals+unsubscribe@isocpp.org</a>.<br>
> To post to this group, send email to <a href=3D"mailto:std-proposals@i=
socpp.org">std-proposals@isocpp.org</a>.<br>
> Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/g=
roup/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-propos=
als/</a>.<br>
</p>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
--001a11334f148211ea0514a37a52--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 26 Apr 2015 20:00:52 +0300
Raw View
On 26 April 2015 at 19:54, dgutson . <danielgutson@gmail.com> wrote:
>> Or use something along the lines of the proposed std::expected.
>
> This has been mentioned many times. Could you please point me to the latest
> proposal and tell me its status?
http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4109.pdf
Still being reviewed in LEWG.
--
---
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/.
.
Author: Dave Gomboc <dave.gomboc@gmail.com>
Date: Mon, 27 Apr 2015 05:01:33 -0700 (PDT)
Raw View
------=_Part_3808_1746154316.1430136093879
Content-Type: multipart/alternative;
boundary="----=_Part_3809_104069110.1430136093879"
------=_Part_3809_104069110.1430136093879
Content-Type: text/plain; charset=UTF-8
On Sunday, 26 April 2015 10:00:53 UTC-7, Ville Voutilainen wrote:
>
> On 26 April 2015 at 19:54, dgutson . <daniel...@gmail.com <javascript:>>
> wrote:
> >> Or use something along the lines of the proposed std::expected.
> >
> > This has been mentioned many times. Could you please point me to the
> latest
> > proposal and tell me its status?
>
> http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4109.pdf
>
> Still being reviewed in LEWG.
>
I have come to believe that the automatic throw from constructor failure,
while usually desirable, is sometimes simply not appropriate for
specialized systems. (Yes, my current work is within the safety-critical,
low-resource embedded context.) In C++, the use of exception classes is,
unfortunately, to some extent conflated with the propagation of
exceptions. This is particularly problematic in the case of constructors
because most workarounds sacrifice RAII, which is a terrible thing to do.
I would appreciate your thoughts on why the following adjustment to C++
would either work well or poorly. I certainly do not like some aspects of
it myself (for example, it seems simply wrong to treat constructors
differently from typical member functions with regard to "throw", and
that's not the only problem with it), but I suggest it nonetheless in the
(vain?) hope of trying to stay as backward-compatible as possible.
- C++ constructors would effectively return or result in the construction
of std::expected<E, T> instead of T.
- Successful constructor completion would result in the std::expected<E, T>
containing the constructed T.
- Invoking throw from within a constructor would result in the standard
exception handling cleanup occurring within that constructor, then the
creation of std::expected<E, T> returned to the scope that called the
constructor with E populated with whatever was thrown and captured.
- An implicit conversion from std::expected<E, T> to T would exist. This
implicit conversion would throw whenever E is present instead of T.
The intention is that the vast majority of code could continue to be
written as-is. However, in situations where we wish to avoid actually
throwing, we can manually inspect the std::expected<E, T> to check for an
exception. Compilers that permit users to indicate some "no-throwing"
option (usually unfortunately labelled as "no-exceptions") could issue a
diagnostic when no code examines the std::expected<E, T> returned from a
constructor to ascertain whether a valid T was actually constructed versus
an exception being captured before accessing the T.
By the way, my employer is sending me to C++Now 2015. I would be happy to
discuss such ideas in person with anyone else who will be there.
Dave Gomboc
--
---
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/.
------=_Part_3809_104069110.1430136093879
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, 26 April 2015 10:00:53 UTC-7, Ville Voutilainen=
wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 26 April 2015 at 19=
:54, dgutson . <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated=
-mailto=3D"qodyoeERPBYJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javas=
cript:';return true;" onclick=3D"this.href=3D'javascript:';return true;">da=
niel...@gmail.com</a>> wrote:
<br>>> Or use something along the lines of the proposed std::expected=
..
<br>>
<br>> This has been mentioned many times. Could you please point me to t=
he latest
<br>> proposal and tell me its status?
<br>
<br><a href=3D"http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4109.pd=
f" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://ww=
w.google.com/url?q\75http%3A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%=
2Fpapers%2F2014%2Fn4109.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNFJrWFY8lLq6S=
VChlDD4_3uYqVn9w';return true;" onclick=3D"this.href=3D'http://www.google.c=
om/url?q\75http%3A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%2Fpapers%2=
F2014%2Fn4109.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNFJrWFY8lLq6SVChlDD4_3u=
YqVn9w';return true;">http://open-std.org/JTC1/SC22/<wbr>WG21/docs/papers/2=
014/n4109.<wbr>pdf</a>
<br>
<br>Still being reviewed in LEWG.<br></blockquote><div><br>I have come to b=
elieve that the automatic throw from constructor failure, while usually des=
irable, is sometimes simply not appropriate for specialized systems. =
(Yes, my current work is within the safety-critical, low-resource embedded =
context.) In C++, the use of exception classes is, unfortunately, to =
some extent conflated with the propagation of exceptions. This is par=
ticularly problematic in the case of constructors because most workarounds =
sacrifice RAII, which is a terrible thing to do.<br><br>I would appreciate =
your thoughts on why the following adjustment to C++ would either work well=
or poorly. I certainly do not like some aspects of it myself (for ex=
ample, it seems simply wrong to treat constructors differently from typical=
member functions with regard to "throw", and that's not the only problem w=
ith it), but I suggest it nonetheless in the (vain?) hope of trying to stay=
as backward-compatible as possible.<br><br>- C++ constructors would effect=
ively return or result in the construction of std::expected<E, T> ins=
tead of T.<br><br>- Successful constructor completion would result in the s=
td::expected<E, T> containing the constructed T.<br><br>- Invoking th=
row from within a constructor would result in the standard exception handli=
ng cleanup occurring within that constructor, then the creation of std::exp=
ected<E, T> returned to the scope that called the constructor with E =
populated with whatever was thrown and captured.<br><br>- An implicit conve=
rsion from std::expected<E, T> to T would exist. This implicit =
conversion would throw whenever E is present instead of T.<br><br>The inten=
tion is that the vast majority of code could continue to be written as-is.&=
nbsp; However, in situations where we wish to avoid actually throwing, we c=
an manually inspect the std::expected<E, T> to check for an exception=
.. Compilers that permit users to indicate some "no-throwing" option (=
usually unfortunately labelled as "no-exceptions") could issue a diagnostic=
when no code examines the std::expected<E, T> returned from a constr=
uctor to ascertain whether a valid T was actually constructed versus an exc=
eption being captured before accessing the T.<br><br>By the way, my employe=
r is sending me to C++Now 2015. I would be happy to discuss such idea=
s in person with anyone else who will be there.<br><br>Dave Gomboc<br><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" 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_3809_104069110.1430136093879--
------=_Part_3808_1746154316.1430136093879--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Mon, 27 Apr 2015 15:05:48 +0300
Raw View
On 27 April 2015 at 15:01, Dave Gomboc <dave.gomboc@gmail.com> wrote:
> - C++ constructors would effectively return or result in the construction of
> std::expected<E, T> instead of T.
>
> - Successful constructor completion would result in the std::expected<E, T>
> containing the constructed T.
>
> - Invoking throw from within a constructor would result in the standard
> exception handling cleanup occurring within that constructor, then the
> creation of std::expected<E, T> returned to the scope that called the
> constructor with E populated with whatever was thrown and captured.
>
> - An implicit conversion from std::expected<E, T> to T would exist. This
> implicit conversion would throw whenever E is present instead of T.
I don't think I want to pay the overhead of constructing an
expected<E, T> instead
of T even for succeeding cases.
Also, how do you ever construct arrays anymore? Reserve space for the expected,
instead of for the plain object?
--
---
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/.
.
Author: "dgutson ." <danielgutson@gmail.com>
Date: Mon, 27 Apr 2015 12:16:57 -0300
Raw View
--047d7bd6bca8a1c6320514b63c89
Content-Type: text/plain; charset=UTF-8
thanks.
On 26 April 2015 at 19:54, dgutson . <danielgutson@gmail.com> wrote:
>> Or use something along the lines of the proposed std::expected.
>
> This has been mentioned many times. Could you please point me to the
latest
> proposal and tell me its status?
http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4109.pdf
Still being reviewed in LEWG.
--
---
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/.
--
---
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/.
--047d7bd6bca8a1c6320514b63c89
Content-Type: text/html; charset=UTF-8
<p dir="ltr">thanks.</p>
<div class="gmail_quot<blockquote class=" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 26 April 2015 at 19:54, dgutson . <<a href="mailto:danielgutson@gmail.com">danielgutson@gmail.com</a>> wrote:<br>
>> Or use something along the lines of the proposed std::expected.<br>
><br>
> This has been mentioned many times. Could you please point me to the latest<br>
> proposal and tell me its status?<br>
<br>
<a href="http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4109.pdf" target="_blank">http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4109.pdf</a><br>
<br>
Still being reviewed in LEWG.<br>
<br>
--<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 email to <a href="mailto:std-proposals%2Bunsubscribe@isocpp.org">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href="mailto:std-proposals@isocpp.org">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/" target="_blank">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br>
</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 email to <a href="mailto:std-proposals+unsubscribe@isocpp.org">std-proposals+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href="mailto:std-proposals@isocpp.org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />
--047d7bd6bca8a1c6320514b63c89--
.
Author: Nevin Liber <nevin@eviloverlord.com>
Date: Mon, 27 Apr 2015 10:29:51 -0500
Raw View
--001a11c23fb62ea02a0514b66d1c
Content-Type: text/plain; charset=UTF-8
On 27 April 2015 at 07:01, Dave Gomboc <dave.gomboc@gmail.com> wrote:
> - An implicit conversion from std::expected<E, T> to T would exist. This
> implicit conversion would throw whenever E is present instead of T.
>
But if that is constructing a T, it would have to construct an expected<E,
T> instead, wouldn't it?
And even if you make it an implicit conversion to T&, that isn't nearly
sufficient to make it act like a T.
--
Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404
--
---
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/.
--001a11c23fb62ea02a0514b66d1c
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 2=
7 April 2015 at 07:01, Dave Gomboc <span dir=3D"ltr"><<a href=3D"mailto:=
dave.gomboc@gmail.com" target=3D"_blank">dave.gomboc@gmail.com</a>></spa=
n> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;b=
order-left:1px #ccc solid;padding-left:1ex"><div>- An implicit conversion f=
rom std::expected<E, T> to T would exist.=C2=A0 This implicit convers=
ion would throw whenever E is present instead of T.<br></div></blockquote><=
/div><br>But if that is constructing a T, it would have to construct an exp=
ected<E, T> instead, wouldn't it?<br><br clear=3D"all"><div>And e=
ven if you make it an implicit conversion to T&, that isn't nearly =
sufficient to make it act like a T.</div>-- <br><div class=3D"gmail_signatu=
re">=C2=A0Nevin ":-)" Liber=C2=A0 <mailto:<a href=3D"mailto:ne=
vin@eviloverlord.com" target=3D"_blank">nevin@eviloverlord.com</a>>=C2=
=A0 (847) 691-1404</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" 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 />
--001a11c23fb62ea02a0514b66d1c--
.