220 13146 <a86ce91b-7963-4b0a-9913-5eabf0a05896@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Andy Prowl <andy.prowl@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Try for Object-initialization
Date: Fri, 26 Sep 2014 04:59:00 -0700 (PDT)
Lines: 232
Approved: news@gmane.org
Message-ID: <a86ce91b-7963-4b0a-9913-5eabf0a05896@isocpp.org>
References: <23f86bf6-2f2b-486f-8aef-df6227c25a89@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_100_1568613394.1411732740951"
X-Trace: ger.gmane.org 1411732750 21038 80.91.229.3 (26 Sep 2014 11:59:10 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 26 Sep 2014 11:59:10 +0000 (UTC)
Cc: abymaroth@googlemail.com
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCG63E4DYQKRBBNKSWQQKGQEDVFFOZA@isocpp.org Fri Sep 26 13:59:04 2014
Return-path: <std-proposals+bncBCG63E4DYQKRBBNKSWQQKGQEDVFFOZA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pd0-f199.google.com ([209.85.192.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCG63E4DYQKRBBNKSWQQKGQEDVFFOZA@isocpp.org>)
	id 1XXUAx-0002J8-Hf
	for gclcip-std-proposals@m.gmane.org; Fri, 26 Sep 2014 13:59:03 +0200
Original-Received: by mail-pd0-f199.google.com with SMTP id y13sf86716247pdi.10
        for <gclcip-std-proposals@m.gmane.org>; Fri, 26 Sep 2014 04:59:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=mWjkDDoYaueNYfVghTQ4sgot5jtvTm9ide7sDrrP0II=;
        b=WvK309Niy/bnHzAXKlJ8Ky5uH0TeeTMVW6kMX28Zz0F7742oXyv9G+WpMZ22IjfPAh
         18iI6trDt34l0vpMGdAa+wmHhimT8Y1t6rErLm28ekg2ee42/l4cD6bPzJz7q6RYgnOF
         GMePBdsUS4RRA6mfJNa8CjttzMbGolExF6KaCxJwYp3m5vNtpj9IW8qhS0fxBtk3sGY5
         /7jez6IuBdXidoRGDREj+JJSRnoaysYl6ZFE60yJXl9Sgh9sGeJYNHZjXPv6hvNHj68W
         YM09+6dB0q8ZkawWZeP5fWlpRR/UEz+OkNEF78llLaYRcPH++hH2LY/WsVlWQXo52i/L
         52oQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=mWjkDDoYaueNYfVghTQ4sgot5jtvTm9ide7sDrrP0II=;
        b=Mgen6HH3y0t49meuyOEWqgtezpOppNCok9tAdmySRtmTo/KSkd2ghzdDYW6jvCVHxK
         nYxUHp8/cvqHVl6MrAfPUDG+RBZG8JVXFe+ksedw1tEcNPVswgVGDZ018hBbVEi9JpJ+
         kuZkjHR14FtwC3nQN+UFc9EYTsgD+keTQvdxQ6kHZAW0cZ9XkM5INCfrgQp+lm3ZdSO1
         caDqPUmHCnywyJHbhX2+dH23OETGnQCTHObYFbpMkPqTJCCTDCx7EirxpfLzaOMmTtyw
         FFPlNVvj60okjJAjrhqd3OcY9LSR1pZbFl6dx5Isna1mbjAVSCETMQIugNQjW5jEmzyz
         bfMg==
X-Gm-Message-State: ALoCoQk2PAOU5QNniPwZQhGOqEfUA683iTI5qVbahhHMXOnyURbbxGPJfcol0hHbId92F4oKu4uX
X-Received: by 10.66.179.78 with SMTP id de14mr2811865pac.36.1411732742217;
        Fri, 26 Sep 2014 04:59:02 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.91.161 with SMTP id z30ls1091832qgd.99.gmail; Fri, 26 Sep
 2014 04:59:01 -0700 (PDT)
X-Received: by 10.140.82.48 with SMTP id g45mr63854qgd.9.1411732741373;
        Fri, 26 Sep 2014 04:59:01 -0700 (PDT)
In-Reply-To: <23f86bf6-2f2b-486f-8aef-df6227c25a89@isocpp.org>
X-Original-Sender: andy.prowl@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:13146
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/13146>

------=_Part_100_1568613394.1411732740951
Content-Type: text/plain; charset=UTF-8

It is not necessary to have a large try-catch block: it's enough to extract 
the loop into a separate function, and the try-catch block becomes minimal:

void loop(SomeObject& object)
{
    while (running) // this is running for the whole application lifetime 
(object must be valid the whole time)
    {
        // do something with object
    }
}

int main(int argc, char **argv)
{
    try
    {
        SomeObject object;

        loop(object);
    }
    catch (std::exception const&)
    {
        // Whatever...
    }
}

This also makes the dependency of your loop on "object" explicit, which is 
a good thing IMO. If you have many of these objects and passing them all to 
"loop()" becomes impractical, you can create one or more structures to hold 
them, then pass that (or those) structure(s).

If you want your loop's errors to be handled separately from the object 
initialization errors, you can wrap your loop in another try-catch block, 
which could be made minimal again by extraction. That would catch your loop 
errors. The outer try/catch would catch initialization errors.

For what concerns knowing which of the objects have failed, you're right, 
you won't be able to tell which one it is unless you use nested try-catch 
blocks, but is this fundamental? If the objects have different types (or 
different roles based on their state), their failures could be expressed by 
throwing exceptions of different types - this way you would be able to tell 
what went wrong, which is what is fundamental IMO. Knowing concretely which 
object threw the exception is less important than knowing what problem 
occurred.

Anyway these are just my thoughts, good luck with your proposal :)

Andy

-- 

--- 
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_100_1568613394.1411732740951
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">It is not necessary to have a large try-catch block: it's =
enough to extract the loop into a separate function, and the try-catch bloc=
k becomes minimal:<br><br><div class=3D"prettyprint" style=3D"border: 1px s=
olid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, =
250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><div =
class=3D"GO0BFSYAJB" style=3D"font-size: 13.3333330154419px;"><span style=
=3D"font-size: 13.3333330154419px; color: rgb(0, 0, 136);"><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> loop</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">SomeObject</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">object</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">)</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>=
<span style=3D"font-size: 13.3333330154419px; color: rgb(0, 0, 0);"><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">&nbsp; &nbsp; </span></s=
pan><span style=3D"font-size: 13.3333330154419px; color: rgb(0, 0, 136);"><=
span style=3D"color: #008;" class=3D"styled-by-prettify">while</span></span=
><span style=3D"font-size: 13.3333330154419px; color: rgb(0, 0, 0);"><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span></span><span st=
yle=3D"font-size: 13.3333330154419px; color: rgb(102, 102, 0);"><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span></span><span style=
=3D"font-size: 13.3333330154419px; color: rgb(0, 0, 0);"><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">running</span></span><span style=3D=
"font-size: 13.3333330154419px; color: rgb(102, 102, 0);"><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)</span></span><span style=3D"font=
-size: 13.3333330154419px; color: rgb(0, 0, 0);"><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: rgb(136, 0, 0=
);"><span style=3D"color: #800;" class=3D"styled-by-prettify">// this is ru=
nning for the whole application lifetime (object must be valid the whole ti=
me)</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>&nbsp; &nbsp; </span></span><span style=3D"font-size: 13.3333330154419p=
x; color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">{</span></span><span style=3D"font-size: 13.3333330154419px; co=
lor: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span></span><code style=3D"font-size: 13.3333330154419px;"><span s=
tyle=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-=
by-prettify">&nbsp; &nbsp; &nbsp; &nbsp; </span></span><span style=3D"color=
: rgb(102, 102, 0);"><span style=3D"color: rgb(136, 0, 0);"><span style=3D"=
color: #800;" class=3D"styled-by-prettify">// do something with object</spa=
n></span></span></code><span style=3D"font-size: 13.3333330154419px; color:=
 rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span></span><span style=3D"font-size: 13.3333330154419px; color: rgb(1=
02, 102, 0);"><span style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">&nbsp; &nbsp; </span></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span></span><span style=
=3D"font-size: 13.3333330154419px; color: rgb(0, 0, 136);"><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">int</span></span><span style=3D"font-size: 13.3333=
330154419px; color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> main</span></span><span style=3D"font-size: 13.333333015=
4419px; color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">(</span></span><span style=3D"font-size: 13.3333330154419p=
x; color: rgb(0, 0, 136);"><span style=3D"color: #008;" class=3D"styled-by-=
prettify">int</span></span><span style=3D"font-size: 13.3333330154419px; co=
lor: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> argc</span></span><span style=3D"font-size: 13.3333330154419px; color: =
rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"styled-by-prettify=
">,</span></span><span style=3D"font-size: 13.3333330154419px; color: rgb(0=
, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
></span><span style=3D"font-size: 13.3333330154419px; color: rgb(0, 0, 136)=
;"><span style=3D"color: #008;" class=3D"styled-by-prettify">char</span></s=
pan><span style=3D"font-size: 13.3333330154419px; color: rgb(0, 0, 0);"><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span></span><span=
 style=3D"font-size: 13.3333330154419px; color: rgb(102, 102, 0);"><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">**</span></span><span sty=
le=3D"font-size: 13.3333330154419px; color: rgb(0, 0, 0);"><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">argv</span></span><span style=3D"=
font-size: 13.3333330154419px; color: rgb(102, 102, 0);"><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)</span></span><span style=3D"font-=
size: 13.3333330154419px; color: rgb(0, 0, 0);"><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br></span></span><span style=3D"font-size: =
13.3333330154419px; color: rgb(102, 102, 0);"><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: rgb(0, 0, 0);"><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></span>=
</span></div><span style=3D"font-size: 13.3333330154419px; color: rgb(0, 0,=
 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify">&nbsp; &nbs=
p; </span><span style=3D"color: rgb(0, 0, 136);"><span style=3D"color: #008=
;" class=3D"styled-by-prettify">try</span></span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"col=
or: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">{</span></span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span></span><div class=3D"GO0BFSYAJB" style=3D"font-size: 13.3333=
330154419px;"><span style=3D"font-size: 13.3333330154419px; color: rgb(0, 0=
, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify">&nbsp; &nb=
sp; &nbsp; &nbsp; </span></span><span style=3D"font-size: 13.3333330154419p=
x; color: rgb(102, 0, 102);"><span style=3D"color: #606;" class=3D"styled-b=
y-prettify">SomeObject</span></span><span style=3D"font-size: 13.3333330154=
419px; color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span></span><span style=3D"font-size: 13.3333330154419px; co=
lor: rgb(0, 0, 136);"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">object</span></span><span style=3D"font-size: 13.3333330154419px; colo=
r: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span></span><span style=3D"font-size: 13.3333330154419px; color: rg=
b(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
<br></span></span><span style=3D"font-size: 13.3333330154419px; color: rgb(=
0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify">&nbsp;=
 &nbsp; &nbsp; &nbsp; loop</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">object</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">);</span></span></div><span style=3D"font-size: 13.3333330154419px; colo=
r: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> &nbsp; &nbsp; </span><span style=3D"color: rgb(102, 102, 0);"><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: rgb(0, 0, 136);"><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">catch</span></span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: rgb(102, 102, 0);"><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">(</span></span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=3D=
"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"styled-by-=
prettify">::</span></span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">exception </span><span style=3D"color: rgb(0, 0, 136);"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">const</span></span><span st=
yle=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&amp;)</span></span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: rgb(102, =
102, 0);"><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp=
; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: rgb(136, 0, 0);"><span =
style=3D"color: #800;" class=3D"styled-by-prettify">// Whatever...</span></=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &=
nbsp; </span><span style=3D"color: rgb(102, 102, 0);"><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">}</span></span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span></span><span style=3D"font-si=
ze: 13.3333330154419px; color: rgb(102, 102, 0);"><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">}</span></span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br></span></div></code></div><br>This also =
makes the dependency of your loop on "object" explicit, which is a good thi=
ng IMO. If you have many of these objects and passing them all to "loop()" =
becomes impractical, you can create one or more structures to hold them, th=
en pass that (or those) structure(s).<br><br>If you want your loop's errors=
 to be handled separately from the object initialization errors, you can wr=
ap your loop in another try-catch block, which could be made minimal again =
by extraction. That would catch your loop errors. The outer try/catch would=
 catch initialization errors.<br><br>For what concerns knowing which of the=
 objects have failed, you're right, you won't be able to tell which one it =
is unless you use nested try-catch blocks, but is this fundamental? If the =
objects have different types (or different roles based on their state), the=
ir failures could be expressed by throwing exceptions of different types - =
this way you would be able to tell what went wrong, which is what is fundam=
ental IMO. Knowing concretely which object threw the exception is less impo=
rtant than knowing what problem occurred.<br><br>Anyway these are just my t=
houghts, good luck with your proposal :)<br><br>Andy</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_100_1568613394.1411732740951--

.
