220 12075 <53D28931.3020501@gmx.de> article
Path: news.gmane.org!not-for-mail
From: Jan Herrmann <jherrmann79@gmx.de>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Variadic catch
Date: Fri, 25 Jul 2014 18:43:29 +0200
Lines: 95
Approved: news@gmane.org
Message-ID: <53D28931.3020501@gmx.de>
References: <d95d4f7c-7d8e-42de-bdb4-9f83bce67b50@isocpp.org>	<53D270BF.5010906@gmx.de>	<3f9efef6-04ec-47d7-807e-0d695bb2eba7@isocpp.org>	<9E8291EE-CD67-4772-A364-0929FD18E295@gmail.com>	<bf338ea5-a89d-46a8-94a9-465effd859d2@isocpp.org>	<BE8F68C9-4CEC-441D-BE1E-0BA43568C78A@gmail.com> <CAFk2RUa0u016BeUnL6AkrZEBUaN1NV2Ap6f_dFCv19QDXHMkgg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Trace: ger.gmane.org 1406306625 26705 80.91.229.3 (25 Jul 2014 16:43:45 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 25 Jul 2014 16:43:45 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDJMREEMZMDRBOUSZKPAKGQE7T6D5JQ@isocpp.org Fri Jul 25 18:43:39 2014
Return-path: <std-proposals+bncBDJMREEMZMDRBOUSZKPAKGQE7T6D5JQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-la0-f70.google.com ([209.85.215.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDJMREEMZMDRBOUSZKPAKGQE7T6D5JQ@isocpp.org>)
	id 1XAiao-0001Jc-Ti
	for gclcip-std-proposals@m.gmane.org; Fri, 25 Jul 2014 18:43:38 +0200
Original-Received: by mail-la0-f70.google.com with SMTP id mc6sf3282851lab.9
        for <gclcip-std-proposals@m.gmane.org>; Fri, 25 Jul 2014 09:43:38 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to
         :subject:references:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=n39Fv28WLgExkwkQvH7C1LQE8HuPMr8K+4X0bFtTVrg=;
        b=d1/tQb0V2LRCeYx3pCEsyPnDX1TqOj9lTCa/X86Pu8J6lkE8g1e9QV4t0lfwubn2Cs
         c2edyg9SIlecOE5dAEsSlH89EvZhzKgnQiLUzdqLRpFTfRGDBfJH1o2AHMo691FF0h/e
         5jdJiwlvkJx/vxZ/U5eHv08uyYIc8XQLCCihILLVIl+oGBBaPrdhBgYMQna3CkSe6BxX
         F7D8Ash14q0gP4G0r2F0UVCqmVHBx0AXfPfDvTyhpjLNGeA75dYwgwxNCGq2ka9gelPo
         2SGzS96XZnkyFuM9UdvVOCLKdVpQuvRHuxKY52w1b/cb7wqLxxaLqY+BDvmofKGF096o
         zGwA==
X-Gm-Message-State: ALoCoQl7Nf63pK9G5aHqCjzwf7WuJ5t5DchLdynCTnQPZ1CFd3A/Jr1iubqiB1p7toLksT4T302J
X-Received: by 10.180.36.38 with SMTP id n6mr588975wij.0.1406306618652;
        Fri, 25 Jul 2014 09:43:38 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.77.41 with SMTP id p9ls121331wiw.17.canary; Fri, 25 Jul
 2014 09:43:37 -0700 (PDT)
X-Received: by 10.180.35.36 with SMTP id e4mr7035726wij.12.1406306617831;
        Fri, 25 Jul 2014 09:43:37 -0700 (PDT)
Original-Received: from mout.gmx.net (mout.gmx.net. [212.227.17.22])
        by mx.google.com with ESMTPS id mc8si18982821wjb.66.2014.07.25.09.43.37
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 25 Jul 2014 09:43:37 -0700 (PDT)
Received-SPF: pass (google.com: domain of jherrmann79@gmx.de designates 212.227.17.22 as permitted sender) client-ip=212.227.17.22;
Original-Received: from [192.168.1.2] ([84.184.1.176]) by mail.gmx.com (mrgmx103) with
 ESMTPSA (Nemesis) id 0LjJCt-1WePB80Cch-00dZtg for <std-proposals@isocpp.org>;
 Fri, 25 Jul 2014 18:43:37 +0200
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0
In-Reply-To: <CAFk2RUa0u016BeUnL6AkrZEBUaN1NV2Ap6f_dFCv19QDXHMkgg@mail.gmail.com>
X-Provags-ID: V03:K0:Xl+QmceOj4dmPTCsSCvNNssUdDr93c+biSJfXob94VV2nHuEvAQ
 uNltFFAZBS3HdCPpf83j9Jf/d+GydwbzJXDUuey4vhMDoVHTOX9lnHencb3ZpQaQeElc1oo
 jnsqen5QjJoI+W700m7t7FnKdFVItJVw4WN45z6MANe/cX0uMN/z0E6slHQ+8Hzw99WEH/x
 uFiDF8VNOIUSQ9oxfY34A==
X-Original-Sender: jherrmann79@gmx.de
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of jherrmann79@gmx.de designates 212.227.17.22 as permitted sender) smtp.mail=jherrmann79@gmx.de
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:12075
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/12075>

On 25.07.2014 18:04, Ville Voutilainen wrote:
> On 25 July 2014 18:44, David Krauss <potswa@gmail.com> wrote:
>>
>> On 2014-07-25, at 11:36 PM, Jeaye Wilkerson <contact@jeaye.com> wrote:
>>
>>> Yes, the body of the catch block would need to be generic for each type, but, as with any generic API within the generic paradigm, that doesn't mean they should share a common base; they share a common public interface.
>>
>> That's just a bad design. The language shouldn't support it. Just because it's possible doesn't mean it's OK.
>
> What's bad design? A library providing multiple exception types that
> do not form a hierarchy?
> I disagree. There's nothing bad about it. Now, whether we need to
> provide a way to generate
> the code to catch all those different exception types and run the same
> code on all of them is
> a different matter.
>
> Work-arounds certainly seem to incur unfortunate costs - using a
> variable function template
> that re-throws and catches a specific type will lead to one re-throw
> per every type in the pack,
> as opposed to a single throw that this extension proposal would have.
>

The first version has another background (it can be used more 
dynamically). I have a second version which needs some polishing but 
should show my ideas ( 
http://coliru.stacked-crooked.com/a/0420ce9ae0180306 ):
#include <iostream>
#include <stdexcept>
#include <typeinfo>


template<class Fun, class ExceptionHandler, class ... Exceptions>
struct excpected_exception;

template<class Fun, class ExceptionHandler, class Ex1, class ... Exceptions>
struct excpected_exception<Fun, ExceptionHandler, Ex1, Exceptions...>
{
     void operator()(Fun f, ExceptionHandler eh) {
         try {
             excpected_exception<Fun, ExceptionHandler, 
Exceptions...>{}(f, eh);
         } catch (Ex1 const& ex) {
             eh(ex);
         }
     }
};

template<class Fun, class ExceptionHandler>
struct excpected_exception<Fun, ExceptionHandler>
{
     void operator()(Fun f, ExceptionHandler) {
         f();
     }
};

template<class... Ex, class F, class Eh>
void expect_exception(F f, Eh eh) {
     excpected_exception<F, Eh, Ex...>{}(f, eh);
}

struct MyEh {
     template<class Ex>
     void operator()(Ex&& ex) const {
         std::cerr << ex.what() << "(" << typeid(ex).name() << ")" << 
std::endl;
     }
};


int main() {

     expect_exception<std::runtime_error, std::logic_error>([&]{throw 
std::runtime_error("Hello");}, MyEh{});
     expect_exception<std::runtime_error, std::logic_error>([&]{throw 
std::logic_error("World");;}, MyEh{});

     return 0;
}

The main problem with this version is that exceptions have to be sorted 
to bring derived exceptions to front and eventually to bring often 
catched exceptions to front. This has to be standardized as well.

Jan Herrmann

-- 

--- 
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/.

.
