220 33504 <effe744d-f832-42c7-9b2a-ef31551067d0@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: david.bolvansky@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Catch block for multiple exceptions
Date: Tue, 1 Aug 2017 10:04:21 -0700 (PDT)
Lines: 247
Approved: news@gmane.org
Message-ID: <effe744d-f832-42c7-9b2a-ef31551067d0@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_2652_308856715.1501607061056"
X-Trace: blaine.gmane.org 1501607066 18152 195.159.176.226 (1 Aug 2017 17:04:26 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 1 Aug 2017 17:04:26 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDSMRTMFUIFRBFPJQLGAKGQEEDI4EDI@isocpp.org Tue Aug 01 19:04:19 2017
Return-path: <std-proposals+bncBDSMRTMFUIFRBFPJQLGAKGQEEDI4EDI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f197.google.com ([209.85.220.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDSMRTMFUIFRBFPJQLGAKGQEEDI4EDI@isocpp.org>)
	id 1dcaaf-0004HX-2f
	for gclcip-std-proposals@m.gmane.org; Tue, 01 Aug 2017 19:04:17 +0200
Original-Received: by mail-qk0-f197.google.com with SMTP id i143sf10287512qke.14
        for <gclcip-std-proposals@m.gmane.org>; Tue, 01 Aug 2017 10:04:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=B/SNUAzcNILv2asCPpdFgWI2t0NtIo77MYmAGS5kNRg=;
        b=C6FeP9jAZVWsAkLxD6Z5OE1E5xwPmn1RTwSJoAzPhZwn+SB6RnnMJMmetEh7sEPL2o
         NfOi8Zi9XSux3Ngb5lTv6eTNfzUCksCSBpsHavWuJjp1VhDfVgBFF6lRUYRRkG9YinPB
         bkNarKahdTfbsDpcQ7562G2WoLtM4wwXZOXonU63YvW85EF8WblnYP3dPQLNyQzenKUr
         I+UFi/xeOPyYEO3tuRaVJWLj6pPm+FkazWZfKNcJ1kdwQkigTSQkQuBugTxCZfqDW6Ur
         fxLfpuvoLEP6UQhSCacCMn2v/rAyQvhgdYzzKTyPd4UntFCBhF/49OwTdZy5emzWbGz4
         Sh9Q==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=B/SNUAzcNILv2asCPpdFgWI2t0NtIo77MYmAGS5kNRg=;
        b=dowKuECsAUlchL9YkQBiK6DEY9oSY+63xk3T1Vk6k7PW/QP4Wih+LykW0aDH7AzVI9
         1bZXKG7aJki2nK3P/OJq6I5am8p9qTJsvOuU5AZWODZDsGTWO1c/IFwpegTh//GMSZyh
         mD3F0jQgqS7HDcgAHuXR6q2SKwXbjJOHmZrcURl57ZGNZlG47wFyI4rurRjxNXs3OXwP
         +Nes08rwad3UerbeGvl+w70IVH7SaiaQfy6eFyO+wN0NH4fN2mTg1fffC2BVBkbnhyxI
         cwFIWCqhwwsjhNli8lWkLEoanzL4NnXVrQKkApe3/Mh98f6Q5NsqFQVRgaCNFJ3N3LNV
         tnsQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=B/SNUAzcNILv2asCPpdFgWI2t0NtIo77MYmAGS5kNRg=;
        b=aF5dVTdWrX8UFhfEPyd3HhUpFsyKAak8NINkGqfvHT+SZEVZyVRpnQqqwX3BTvmmrp
         kSsET1U1bSMdPM7QWoZAClgcRwqLBcxV9wK6PSxWEPwJi9Djd9ej8c0j1U+dKMNCGHUx
         kK6nmpH216YchOtjLTjHnmbziLk5QXG4xzlgLFo68HUQggsEj/1WEBxOWzTWLecPnqxV
         RmMNJkwjzq9H3D+wHmgGK2T7hz1iciqicqS0jaem2/GulTHGAx1DeG31HIM6gNM4xXt0
         49lccTaE/uGvT86WZEWl7NsTeYO148a1wWogjFPQdWooPLzI0o/6i1YVZ73VwGTgsh6j
         DF0w==
X-Gm-Message-State: AIVw112k1dqapXZfsv30Op9QLTuw8guTPo2gvAwHgbmvWUIluFdeQQNl
	CCdNDezJn00Szdz3
X-Received: by 10.237.59.44 with SMTP id p41mr13993599qte.49.1501607062768;
        Tue, 01 Aug 2017 10:04:22 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.108.4 with SMTP id w4ls1639149itb.12.canary-gmail; Tue, 01
 Aug 2017 10:04:21 -0700 (PDT)
X-Received: by 10.31.59.134 with SMTP id i128mr106187vka.29.1501607061402;
        Tue, 01 Aug 2017 10:04:21 -0700 (PDT)
X-Original-Sender: david.bolvansky@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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://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>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:33504
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33504>

------=_Part_2652_308856715.1501607061056
Content-Type: multipart/alternative; 
	boundary="----=_Part_2653_1000255546.1501607061056"

------=_Part_2653_1000255546.1501607061056
Content-Type: text/plain; charset="UTF-8"

If you need to handle multiple exceptions you write catch block per every 
exception.

Example:

try {
      ...
} catch (exceptionA e) {
     // handle expetionA
     f();
}


} catch (exceptionB e) {
     // handle exceptionB
     f();
}


} catch (exceptionC e) {
     // handle exceptionC
     f();
}


} catch (exceptionD e) {
     // handle exceptionD
     g();
}




If e.g. exception A, B, C could be handled via the same logic (e.g function 
"f"), we are copy-pasting exception-handling code (callinf f() in this 
case) in particular catch blocks.


To avoid that, proposed improvment could be:


try {
      ...
} catch (exceptionA, exceptionB, exceptionC) {
     // handle exception (does not matter whether exception A, B or C - we 
have same handling code for them)
     f();
}

} catch (exceptionD e) {
     // handle exceptionD
     g();
}




With the instance of one of  those exceptions:
catch (exceptionA, exceptionB, exceptionC e) {
   f(e);
}



-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/effe744d-f832-42c7-9b2a-ef31551067d0%40isocpp.org.

------=_Part_2653_1000255546.1501607061056
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">If you need to handle multiple exceptions you write catch =
block per every exception.<div><br></div><div>Example:<br><div><br></div><d=
iv class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bor=
der-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word=
-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprin=
t"><span style=3D"color: #008;" class=3D"styled-by-prettify">try</span><spa=
n 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"><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></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">catch</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>exceptionA e</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0=
</span><span style=3D"color: #800;" class=3D"styled-by-prettify">// handle =
expetionA</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>=C2=A0 =C2=A0 =C2=A0f</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><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>=
<br></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 s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">catch</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">exceptionB e</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"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #800;" class=3D"=
styled-by-prettify">// handle exceptionB</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0f</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br><br><br></span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">catch</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">exceptionC e</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><spa=
n 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"><br>=C2=A0 =C2=A0 =C2=A0</span><span =
style=3D"color: #800;" class=3D"styled-by-prettify">// handle exceptionC</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 =C2=A0f</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">();</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><br></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: #008;" class=3D"styled-by-prettify">catch</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">exceptionD e</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"><br>=C2=
=A0 =C2=A0 =C2=A0</span><span style=3D"color: #800;" class=3D"styled-by-pre=
ttify">// handle exceptionD</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0g</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br><br></span></div></code></div><div><br><br></div><div><br></d=
iv><div>If e.g. exception A, B, C could be handled via the same logic (e.g =
function &quot;f&quot;), we are copy-pasting exception-handling code (calli=
nf f() in this case) in particular catch blocks.</div><div><br></div><div><=
br></div><div>To avoid that, proposed improvment could be:</div><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-colo=
r: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: b=
reak-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">try</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;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">catch</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">exceptionA</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> exceptionB</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> exceptionC</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"colo=
r: #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"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #=
800;" class=3D"styled-by-prettify">// handle exception (does not matter whe=
ther exception A, B or C - we have same handling code for them)</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=
=A0f</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan 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: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">catch</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">exceptionD e</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =
=C2=A0</span><span style=3D"color: #800;" class=3D"styled-by-prettify">// h=
andle exceptionD</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 =C2=A0g</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-pr=
ettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br><br><br></span></div></code></div><div><br></div><div><br></div><div>Wit=
h the instance of one of =C2=A0those exceptions:</div><div><div class=3D"pr=
ettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb=
(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-w=
ord;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">catch</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">exceptionA</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> exceptionB</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> exceptionC e</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"><br>=C2=A0 =C2=A0=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">f</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">e</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></div></code></div><br><br><br></div></div>=
</div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/effe744d-f832-42c7-9b2a-ef31551067d0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/effe744d-f832-42c7-9b2a-ef31551067d0=
%40isocpp.org</a>.<br />

------=_Part_2653_1000255546.1501607061056--

------=_Part_2652_308856715.1501607061056--

.
