220 34272 <ooe0b6$d99$1@blaine.gmane.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Bo Persson <bop@gmb.dk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Proposal to add constructors to std::bad_alloc
 exception class.
Date: Sat, 2 Sep 2017 12:15:08 +0200
Lines: 93
Approved: news@gmane.org
Message-ID: <ooe0b6$d99$1@blaine.gmane.org>
References: <d9001051-0946-4dcf-bf78-8bcdb8302989@isocpp.org>
 <42389eb4-97a9-4a1d-bbfb-c653ba62097f@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1504347364 24921 195.159.176.226 (2 Sep 2017 10:16:04 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 2 Sep 2017 10:16:04 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101
 Thunderbird/52.3.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCZ6RLW3UIKBBUEJVLGQKGQEJ3NVZMA@isocpp.org Sat Sep 02 12:15:50 2017
Return-path: <std-proposals+bncBCZ6RLW3UIKBBUEJVLGQKGQEJ3NVZMA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f72.google.com ([209.85.215.72])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCZ6RLW3UIKBBUEJVLGQKGQEJ3NVZMA@isocpp.org>)
	id 1do5Sl-0005FL-K7
	for gclcip-std-proposals@m.gmane.org; Sat, 02 Sep 2017 12:15:39 +0200
Original-Received: by mail-lf0-f72.google.com with SMTP id 64sf1058662lfu.20
        for <gclcip-std-proposals@m.gmane.org>; Sat, 02 Sep 2017 03:15:46 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1504347346; cv=pass;
        d=google.com; s=arc-20160816;
        b=lL1C4bix04Amzy+STQfxBp40U0J3THqaj1/oiD9nnDBqc3JZpci6SvLXYNF36Bjntc
         wvYsCOIREZ43/QNl6GUkIDZ9CtdC1oehRBeFgi6B8RYIkFTjrKgpMz28AVNGyKzBCCc7
         VtwHqkxrwu1XJrIG3sm1lTg5JLsyTDmAjhmSy5d0PKtsetxr5Xwc2IMjS9miOYwWK5e0
         7h9QaTXfJ4kWc5bJsChHvf2iqshFv6X/HneWlkidG48wwnIEMUDunutG75ZF1w5WqnZ8
         0kOLdTeJZbiJr2/bHL96jmv7rQml9rdeEYGDepA28QXF+kyI2OwOdA1ZxjYEy7pg/33W
         k7zQ==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:content-language
         :in-reply-to:user-agent:content-transfer-encoding:mime-version
         :references:message-id:lines:date:subject:from:to
         :arc-authentication-results:arc-message-signature:dkim-signature
         :arc-authentication-results;
        bh=lnwgf1jpscTOU7aV1jIb3zQLduyXFCtP/y4A6Xjqltg=;
        b=0GEE+qCe0L6dWKdSb2H9jp/z1KyG1E7NBPDfeYfgxIKYmEDD0ywHJFwSHNRECvU+BR
         GmxvjYofuPGeiPpcVa9SAVMq2c6ew7pSBQ9nTmERmmv2q4YTtn/IXCOGqjyxhbaSdss1
         ivoR6+pzpcrT2p139/OXhOGBOnZ0m6FDOwTCZ9/N0fR8YXGr1Yc9avBQGYErOm6O91Gh
         r3y0CZlVQCeAzLD9pXM6yMWkxi2v/OysgMvA5oJJb8YNoy53NmLWwndSjbyW2UPPuGuh
         UnrhQicP6y6CYxFyQmMaaGyJM5QDUU5cct0N/nezK5bdoc 
ARC-Authentication-Results: i=2; mx.google.com;
       spf=neutral (google.com: 195.159.176.226 is neither permitted nor denied by best guess record for domain of gclcip-std-proposals@m.gmane.org) smtp.mailfrom=gclcip-std-proposals@m.gmane.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=to:from:subject:date:lines:message-id:references:mime-version
         :content-transfer-encoding:user-agent:in-reply-to:content-language
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=lnwgf1jpscTOU7aV1jIb3zQLduyXFCtP/y4A6Xjqltg=;
        b=RRtahGG0so2wHrrngpUjk5UxMwo85F27IuNVwTJMfnLoYOwVRsfPkezTWBk7O5KxmI
         yb2t1XamLv+kHSR7C6oauCoQbkd1EyWBqFpOmr61FS5EzS3DVWeaUJjpwMSLPhjZYtmZ
         oeDLC3uqNRmYs+KgkEI9X5I3DRr+7vEwIz2kSsOzss3pg/CCrKHGQt6nM96Sr8jvXMPf
         3p30s8Viu0VUPVXQSeh+o8VQPg+XIvvIh03+D3HcBqQdkQHp+ZwczlNFkar3lQc7Ms4O
         VK5T8sFVCWNyd7VZ5TO9nd2xMmGXDMTDhJpSufDMKimdYXsWSNsPJJhq5q/jkUEopfiP
       
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:to:from:subject:date:lines:message-id:references
         :mime-version:content-transfer-encoding:user-agent:in-reply-to
         :content-language:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=lnwgf1jpscTOU7aV1jIb3zQLduyXFCtP/y4A6Xjqltg=;
        b=BSgRp9Ag77ifytnTnMDmsPVO/mp/iyIQTEm/cUeBUJuw0CuCOU9gu3yGNvmlG96f4l
         DqTTSF7nyA6thXHSrlarezRgMMsyH2YiPRqTxQMrumhGEZOQtF4UNx84AL3TdrR/Xfxp
         I0+Adk6Wsqhoe3zfLWgy9Df5D7Rcl12me3dgv2kh+HeMCbpveH/Ok0DHFnPtnk+l+h1p
         eR7PcX6FPMrWK6li70tSCZb4OlVq673GTDWaigXzYeVuz0DXEvRTJ4fv6zaCj/BmbyGL
         wREXDE9beVZdit8BW54W9ROniN6m91jgYWCLi 
X-Gm-Message-State: AHYfb5glHvmRuYgkQCcuZV0YXbC9nFBa9wHg4gNGFTWTf1FImMQ4BMK4
	FiXvgt43QmaKEA==
X-Google-Smtp-Source: ADKCNb7FaHLdhKXvlghiRFH8YEBkYh+S1au7DrzJKKQBA5YipN9pZzpPFhA4+Gv97QsQePM7LFCu7g==
X-Received: by 10.46.66.197 with SMTP id h66mr611140ljf.26.1504347346613;
        Sat, 02 Sep 2017 03:15:46 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.46.68.209 with SMTP id b78ls24075ljf.6.gmail; Sat, 02 Sep 2017
 03:15:44 -0700 (PDT)
X-Received: by 10.25.195.6 with SMTP id t6mr1598956lff.178.1504347344656;
        Sat, 02 Sep 2017 03:15:44 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1504347344; cv=none;
        d=google.com; s=arc-20160816;
        b=awjhblxYtCwzPDECn/MJkEp1Q1FSgDkK3NjhFbobV68DdPUEPRSbFM1vULae9ICig3
         uDc8aLvtA0RX2l61nAm4703xEe2Sj4pJwm8U8lzWxpm8M0nXXXwTiLA0PW440vo6r34o
         Ts9Af8wIrkptM5onkeeK9anPfrPVpl+P3GRfy8Gin1ZwH0N5RvkQyptMRKqNrvgDBvET
         a64YGGDaolpPrFIDjlZWq9vTJbM+Xdrt28hZxXF+172/ImGNfyx6Iqdkjmtd+HlV+fMF
         +bVbuwq90o0om9CF11TAbcX4LdOVRsr5n+wMd5JZWDMoHNzNhFCHRfRhxcNFyAcY7CaR
         qhjA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-language:in-reply-to:user-agent:content-transfer-encoding
         :mime-version:references:message-id:lines:date:subject:from:to
         :arc-authentication-results;
        bh=fgIsVfrntbBJhFrRx4lNNQi949Fh2VNjqe824syvvqE=;
        b=HpjPUn/nQ8qrWyE8cLtGfT6FH5UJLjeSZIRBieiKirgocGVPoZordg9/1yTb5GOQlC
         GDzqRmS/UAH19jZx6ExLhKEGOJPfvGewYpJq8O6q29sxu07q/EKLWFsh6sFUzpZBzeJQ
         mHpK14dbAlrz524TOoBzFr1T0oewZ9EDsyw5qGguDDNYHj8HRdaVBYcs4ViXaaTRfUb/
         9gFJg1Xr95dweg78BLsNlJ9VWmX/J78K/WZpiDgsJQoqymiyBNaJgK3YYc8SDaCByFT/
         t34HtqoIxpL60pa8caU8yYFDn/A32KgfBuwRYkUCOO87zIVPCS6qGiDctFtDqoyBfYoE
         A0fg==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=neutral (google.com: 195.159.176.226 is neither permitted nor denied by best guess record for domain of gclcip-std-proposals@m.gmane.org) smtp.mailfrom=gclcip-std-proposals@m.gmane.org
Original-Received: from blaine.gmane.org ([195.159.176.226])
        by mx.google.com with ESMTPS id k201si184866lfe.145.2017.09.02.03.15.44
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 02 Sep 2017 03:15:44 -0700 (PDT)
Received-SPF: neutral (google.com: 195.159.176.226 is neither permitted nor denied by best guess record for domain of gclcip-std-proposals@m.gmane.org) client-ip=195.159.176.226;
Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2)
	(envelope-from <gclcip-std-proposals@m.gmane.org>)
	id 1do5SN-0004Ct-R0
	for std-proposals@isocpp.org; Sat, 02 Sep 2017 12:15:15 +0200
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 80
Original-X-Complaints-To: usenet@blaine.gmane.org
In-Reply-To: <42389eb4-97a9-4a1d-bbfb-c653ba62097f@isocpp.org>
Content-Language: sv
X-Original-Sender: gclcip-std-proposals@m.gmane.org
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 195.159.176.226 is neither permitted nor denied by best guess
 record for domain of gclcip-std-proposals@m.gmane.org) smtp.mailfrom=gclcip-std-proposals@m.gmane.org
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:34272
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/34272>

On 2017-09-02 01:04, Nicol Bolas wrote:
> On Friday, September 1, 2017 at 3:28:44 PM UTC-4, Rich Sposato wrote:

>=20
>     *5.**Allowing allocators to inform callers exactly why allocations
>     failed.*
>=20
>=20
>     Allocations may fail for reasons other than the program ran out
>     memory. There are specialized allocators that only handle requests
>     for specific sizes, such as pool allocators, that could throw
>     exceptions if they receive requests for sizes they cannot handle.
>=20
>=20
>     This example shows how an allocator might throw a bad_alloc
>     exception with actionable information.
>=20
>=20
>     void * PoolAllocator::Allocate( std::size_t bytes, std::align_val_t
>     alignment )
>=20
>     {
>=20
>     if ( ( bytes < minAllowedSize ) || ( maxAllowedSize < bytes ) )
>=20
>     {
>=20
>     throw *SmartBadAllocException(*
>=20
>     *=E2=80=9CError! This allocator only handles allocations from 16 thro=
ugh 64
>     bytes in size.=E2=80=9D, __LINE__, __FUNCTION__ );*
>=20
>     }
>=20
>     if ( !IsValidAlignment( alignment ) )
>=20
>     {
>=20
>     throw *SmartBadAllocException(*
>=20
>     *=E2=80=9CError! This allocator only handles alignments on 4 byte
>     boundaries.=E2=80=9D, __LINE__, __FUNCTION__ );*
>=20
>     }
>=20
>     void * place =3D FindPlace( bytes, alignment );
>=20
>     if ( place =3D=3D nullptr )
>=20
>     {
>=20
>     throw SmartBadAlloc( =E2=80=9CError! Unable to allocate bytes.=E2=80=
=9D,
>=20
>     __LINE__, __FUNCTION__ );
>=20
>     }
>=20
>     return place;
>=20
>     }
>=20
>=20
> Unless you write an English language parser to figure out what those=20
> mean, the only "actionable" thing that can be done is by the=20
> /programmer/ (aka: spitting the message out to the log), not by the=20
> program itself.
>=20
> The only way to make this detectable by the program itself is to have it=
=20
> throw something other than (or more than) `bad_alloc`. None of which=20
> requires playing games with its string.

Instead of parsing strings to identify a set of known reasons, we could=20
just as well have an enum failure_reason with those reasons specified.

An enum value is a lot easier to copy than a string.  :-)

And now we are very close the the feastures already available in the=20
header <system_error>.



--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/ooe0b6%24d99%241%40blaine.gmane.org.

.
