220 41478 <518a0db5-b7f2-470f-b0be-606f66f1c786@isocpp.org> article
Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail
From: Kristen Wegner <kristen.wegner@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: exception classes
Date: Wed, 20 Feb 2019 10:28:38 -0800 (PST)
Approved: news@gmane.org
Message-ID: <518a0db5-b7f2-470f-b0be-606f66f1c786@isocpp.org>
Reply-To: std-proposals@isocpp.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_63_2021104249.1550687318711"
Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226";
	logging-data="2593"; mail-complaints-to="usenet@blaine.gmane.org"
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCGYZOM5TUARBV5YW3RQKGQE2IOROPA@isocpp.org Wed Feb 20 19:28:43 2019
Return-path: <std-proposals+bncBCGYZOM5TUARBV5YW3RQKGQE2IOROPA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yb1-f197.google.com ([209.85.219.197])
	by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
	(Exim 4.89)
	(envelope-from <std-proposals+bncBCGYZOM5TUARBV5YW3RQKGQE2IOROPA@isocpp.org>)
	id 1gwWbq-0000VI-NN
	for gclcip-std-proposals@m.gmane.org; Wed, 20 Feb 2019 19:28:43 +0100
Original-Received: by mail-yb1-f197.google.com with SMTP id z16sf5850556ybp.12
        for <gclcip-std-proposals@m.gmane.org>; Wed, 20 Feb 2019 10:28:42 -0800 (PST)
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=bOtt/hBntAv92axjJjSWGG95dNOUsappt5O5csvAlfM=;
        b=E5ZbJckbmN53uN3LVVV43KxiYfOgxnxOWOznBhXyjDfoFuVum47u032R8Eriybpf++
         8uZoKuTCTmZaUU26x+zoDDe5hZSXEfUrq0gK6qnlbPJ2i8ItT9KsxIHJSAXJE/FoNmI6
         T6UP7vC5Tkos8+54W52LvWTYCrg43tufdpvSQvNHMjj0V5nvfszAXMsNB/AmxtQ8ktvo
         PCfpS04Btz8RNaqdbwd2wJOJvaK32OPhaR9aXA08cbZF0uwlL5MjdRNHL/4pxdzPGBoA
         QCmXQO2maMxcZbMN2umR3p7rUWgGOgTprBScTJxrDNn/60wHYrmY9UDBS4YrQpVlN9Rh
         BTzA==
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=bOtt/hBntAv92axjJjSWGG95dNOUsappt5O5csvAlfM=;
        b=pq6WkuK4Rbk8HBG6hng0xb8ugQbKXqOsMzvzgzFG1mXhO3oIkuGtGJ3Xeux2G8qmnO
         EioPic3Fmy4gBfdpGVCA40V9UNg/9ExmCq4VMFZQjY6/QJLaPIp37XAC3d/lPEjxnN6z
         bnkgHOTwQ5tf6xmQL5FTKu8t6RzKz5VI4ycftVX1/mXH+w4RbVpwDIuvM4e45x2mQjdT
         iC8cPBhe/9Qq1UXuQiUprC1y+1eFqhbcbxwECpfZh7G6PnCU36ZDwUIwoExYBwq91bsw
         4jHlySUHzLBh/zGWmeIk8TLo77rehVpYSBr4AAOfch7XKg3Bh12UY1AuNbCyrJ3AdHb0
         2JkQ==
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=bOtt/hBntAv92axjJjSWGG95dNOUsappt5O5csvAlfM=;
        b=pXB5THWGU5loZBAc99d784HheK+v8mYViZvDt4KmPSGutca9etzNOcnG7l3mWVrx84
         432DZdCsegobxhQ9xBEiCCh1T4Gqcpe5rQFOWWkRjtkPVCc05R6Qc2P8wr7UMxCqwGrG
         wjI65lbxU/O2cDIKz+ZbPt6zF+y2bqwBMn4GC0BCj7ypElzh5yeWBZoqreJo2aAdIG6r
         ZiOhZn1pQV+8F9P1GTECgYx8yt+N9b8H6xlfJdGrUr/nP8o7gPehb8q28JaLfQTRu27f
         +nwdSTIGBeZ/31mg73Ta/O9ajBDdjiXQ4yjrHH87WxVaQQNxch1/jD57qpgUVspsv4cp
         9NqA==
X-Gm-Message-State: AHQUAua5SDOa/8HsIXr15e6TsjFx1ibs0+CkiMJUEypWV1Jvq9ucN2Nv
	JhMe5ogoMe4qg/vOneT2aXzDFg==
X-Google-Smtp-Source: AHgI3Ib1yG3cxzI8ZtzUnisRDzdPAgrj330m/J9nKpNDQ6GxZd6QuQmuX8L0i4qUf/mJFeaAVMgOyw==
X-Received: by 2002:a25:6412:: with SMTP id y18mr18756725ybb.53.1550687320928;
        Wed, 20 Feb 2019 10:28:40 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a25:d58:: with SMTP id 85ls7063152ybn.8.gmail; Wed, 20 Feb
 2019 10:28:39 -0800 (PST)
X-Received: by 2002:a25:8042:: with SMTP id a2mr312314ybn.2.1550687319206;
        Wed, 20 Feb 2019 10:28:39 -0800 (PST)
X-Original-Sender: kristen.wegner@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:41478
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/41478>

------=_Part_63_2021104249.1550687318711
Content-Type: multipart/alternative; 
	boundary="----=_Part_64_400953254.1550687318711"

------=_Part_64_400953254.1550687318711
Content-Type: text/plain; charset="UTF-8"

Hi. This is my first post here after lurking a while, so forgive me if I am 
barking up the wrong tree.

I am contemplating how exceptions are represented, and whether they might 
be improved somehow. Exceptions are currently just structs or classes like 
any other, yet they are used quite differently.

What if we had smarter "exception classes" that had a few specialized 
facilities for doing the things that exceptions need to do? We have "enum 
class," how about "exception class?" For example:

#ifndef _EXCEPTION_CLASSES
#define exception 
#endif

exception class my_exception // 'exception class' gives us permission to 
override catch.
{
public:
my_exception(const std::string& message, int thing) : message_(message), 
thing_(thing) { }
void complain() const {
std::cerr << "Caught '" << typeid(*this).name() << "': " << message_ << ", 
thing was: " << thing_ << std::endl;
}
#ifdef _EXCEPTION_CLASSES
// Here we handle being caught.
my_exception& operator catch() {
complain();
return *this;
}
#endif
private:
std::string message_;
int thing_;
};

Now, when I do something like:

int dummy(int thing)
{
try
{
if (!thing) throw my_exception("Dummy: Bad thing", thing);
}
catch(my_exception& e) // my_exception::operator catch() gets called.
{
#ifndef _EXCEPTION_CLASSES
e.complain(); // Not needed with exception classes.
#endif
}
}
 
.... I automatically get called when my exception class is caught. Presto, I 
can override operator catch() in all of my exceptions and enable automatic 
tracing.

Are there any more ideas out there how to improve exceptions?

-- 
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/518a0db5-b7f2-470f-b0be-606f66f1c786%40isocpp.org.

------=_Part_64_400953254.1550687318711
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi. This is my first post here after lurking a while, so f=
orgive me if I am barking up the wrong tree.<div><br></div><div>I am contem=
plating how exceptions are represented, and whether they might be improved =
somehow. Exceptions are currently just structs or classes like any other, y=
et they are used quite differently.</div><div><br></div><div>What if we had=
 smarter &quot;exception classes&quot; that had a few specialized facilitie=
s for doing the things that exceptions need to do? We have &quot;<font face=
=3D"courier new, monospace">enum class</font>,&quot; how about &quot;<font =
face=3D"courier new, monospace">exception class</font>?&quot; For example:<=
/div><div><br></div><div><span style=3D"color: rgb(153, 0, 0); font-family:=
 &quot;courier new&quot;, monospace;">#ifndef _EXCEPTION_CLASSES</span><br>=
</div><div><font color=3D"#990000"><span style=3D"font-family: &quot;courie=
r new&quot;, monospace;">#define=C2=A0</span><span style=3D"font-family: &q=
uot;courier new&quot;, monospace;">exception</span><span style=3D"font-fami=
ly: &quot;courier new&quot;, monospace;">=C2=A0</span></font></div><div><sp=
an style=3D"color: rgb(153, 0, 0); font-family: &quot;courier new&quot;, mo=
nospace;">#endif</span><span style=3D"color: rgb(153, 0, 0); font-family: &=
quot;courier new&quot;, monospace;"><br></span></div><div><span style=3D"co=
lor: rgb(153, 0, 0); font-family: &quot;courier new&quot;, monospace;"><br>=
</span></div><div><div><font face=3D"courier new, monospace"><font color=3D=
"#0000ff">exception class</font> my_exception=C2=A0</font><span style=3D"co=
lor: rgb(56, 118, 29); font-family: &quot;courier new&quot;, monospace;">//=
</span><span style=3D"color: rgb(56, 118, 29); font-family: &quot;courier n=
ew&quot;, monospace;">=C2=A0</span><font color=3D"#38761d"><span style=3D"f=
ont-family: &quot;courier new&quot;, monospace;">&#39;</span><span style=3D=
"font-family: &quot;courier new&quot;, monospace;">exception</span><span st=
yle=3D"font-family: &quot;courier new&quot;, monospace;">=C2=A0class&#39; g=
</span><span style=3D"font-family: &quot;courier new&quot;, monospace;">iv<=
/span></font><span style=3D"color: rgb(56, 118, 29); font-family: &quot;cou=
rier new&quot;, monospace;">es us permission to override catch.</span></div=
><div><font face=3D"courier new, monospace">{</font></div><div><font face=
=3D"courier new, monospace"><font color=3D"#0000ff">public</font>:</font></=
div><div><font face=3D"courier new, monospace"><span style=3D"white-space:p=
re">	</span>my_exception(<font color=3D"#0000ff">const </font>std::string&a=
mp; message, <font color=3D"#0000ff">int </font>thing) : message_(message),=
 thing_(thing) { }</font></div><div><span style=3D"font-family: &quot;couri=
er new&quot;, monospace; white-space: pre;">	</span><span style=3D"font-fam=
ily: &quot;courier new&quot;, monospace;"><font color=3D"#0000ff">void </fo=
nt>complain() <font color=3D"#0000ff">const </font>{</span><br></div><div><=
font face=3D"courier new, monospace"><div><span style=3D"white-space:pre">	=
	</span>std::cerr &lt;&lt; &quot;Caught &#39;&quot; &lt;&lt; typeid(*this).=
name() &lt;&lt; &quot;&#39;: &quot; &lt;&lt; message_ &lt;&lt; &quot;, thin=
g was: &quot; &lt;&lt; thing_ &lt;&lt; std::endl;</div><div><span style=3D"=
white-space:pre">	</span>}</div><div><font color=3D"#990000">#ifdef _EXCEPT=
ION_CLASSES</font></div></font></div><div><font face=3D"courier new, monosp=
ace"><span style=3D"white-space:pre">	</span><font color=3D"#38761d">// Her=
e we handle being caught.</font></font></div><div><font face=3D"courier new=
, monospace"><span style=3D"white-space:pre">	</span>my_exception&amp; <fon=
t color=3D"#0000ff">operator catch</font>() {</font></div><div><font face=
=3D"courier new, monospace"><span style=3D"white-space:pre">		</span>compla=
in()</font><span style=3D"font-family: &quot;courier new&quot;, monospace;"=
>;</span></div><div><font face=3D"courier new, monospace"><span style=3D"wh=
ite-space:pre">		</span><font color=3D"#0000ff">return </font>*this;<br></f=
ont></div><div><font face=3D"courier new, monospace"><span style=3D"white-s=
pace:pre">	</span>}</font></div><div><font face=3D"courier new, monospace" =
color=3D"#990000">#endif</font></div><div><font face=3D"courier new, monosp=
ace"><font color=3D"#0000ff">private</font>:</font></div><div><font face=3D=
"courier new, monospace"><span style=3D"white-space:pre">	</span>std::strin=
g message_;</font></div><div><font face=3D"courier new, monospace"><span st=
yle=3D"white-space:pre">	</span><font color=3D"#0000ff">int </font>thing_;<=
/font></div><div><font face=3D"courier new, monospace">};</font></div></div=
><div><br></div><div>Now, when I do something like:</div><div><br></div><di=
v><div><font face=3D"courier new, monospace"><font color=3D"#0000ff">int </=
font>dummy(<font color=3D"#0000ff">int </font>thing)</font></div><div><font=
 face=3D"courier new, monospace">{</font></div><div><font face=3D"courier n=
ew, monospace"><span style=3D"white-space:pre">	</span><font color=3D"#0000=
ff">try</font></font></div><div><font face=3D"courier new, monospace"><span=
 style=3D"white-space:pre">	</span>{</font></div><div><font face=3D"courier=
 new, monospace"><span style=3D"white-space:pre">		</span><font color=3D"#0=
000ff">if </font>(!thing) <font color=3D"#0000ff">throw </font>my_exception=
(&quot;Dummy: Bad thing&quot;, thing);</font></div><div><font face=3D"couri=
er new, monospace"><span style=3D"white-space:pre">	</span>}</font></div><d=
iv><font face=3D"courier new, monospace"><span style=3D"white-space:pre">	<=
/span><font color=3D"#0000ff">catch</font>(my_exception&amp; e) <font color=
=3D"#38761d">// my_exception::operator catch() gets called.</font></font></=
div><div><font face=3D"courier new, monospace"><span style=3D"white-space:p=
re">	</span>{</font></div><div><span style=3D"color: rgb(153, 0, 0); font-f=
amily: &quot;courier new&quot;, monospace;">#ifndef _EXCEPTION_CLASSES</spa=
n><font face=3D"courier new, monospace"><br></font></div><div><font face=3D=
"courier new, monospace"><span style=3D"white-space:pre">		</span>e.complai=
n(); <font color=3D"#38761d">// Not needed with exception classes.</font></=
font></div><div><span style=3D"color: rgb(153, 0, 0); font-family: &quot;co=
urier new&quot;, monospace;">#endif</span><font face=3D"courier new, monosp=
ace"><br></font></div><div><font face=3D"courier new, monospace"><span styl=
e=3D"white-space:pre">	</span>}</font></div><div><font face=3D"courier new,=
 monospace">}</font></div><div>=C2=A0</div></div><div>... I automatically g=
et called when my exception class is caught. Presto, I can override <font f=
ace=3D"courier new, monospace">operator catch()</font> in all of my excepti=
ons and enable automatic tracing.</div><div><br></div><div>Are there any mo=
re ideas out there how to improve exceptions?</div><div><br></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/518a0db5-b7f2-470f-b0be-606f66f1c786%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/518a0db5-b7f2-470f-b0be-606f66f1c786=
%40isocpp.org</a>.<br />

------=_Part_64_400953254.1550687318711--

------=_Part_63_2021104249.1550687318711--

.
