From 5924359441147282395
X-Google-Thread: f78e5,82cd3599ce330676
X-Google-NewGroupId: yes
X-Google-Attributes: gid7894ca11fe,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 04 Apr 2010 12:10:04 -0500
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
To: (Usenet)
From: Kazutoshi Satoda <k_satoda@f2.dion.ne.jp>
Newsgroups: comp.std.c++
Subject: Re: throwing in a noexcept(true) function
Organization: unknown
Sender: cppmods@cs.rpi.edu
Approved: james.dennett@gmail.com
Message-ID: <4BB73613.2040903@f2.dion.ne.jp>
References: <4BB4D8B0.3070603@f2.dion.ne.jp>
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Original-Date: Sat, 03 Apr 2010 21:35:31 +0900
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Date: Sun,  4 Apr 2010 12:04:30 CST
Lines: 62
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-zYtc9gFXlUoPcyxzC1GehwET9sf6dKDjvXJzvcrLqlrwpE+XUkVHqS9MSbN5zkSHs1A8u6u7FMZpe/M!V2SglHUVhHePN+s4IWeIza8X2YjK9ncmjYT0ZW1V3v+HmvjeMse7+MVJ
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
Xref: g2news2.google.com comp.std.c++:2369

Herb Sutter wrote:
>
> The trouble with (d) is that then you get all the problems
> Java gets with statically checked exceptions,

I re-read some articles about what was wrong with checked exceptions.
http://www.artima.com/intv/handcuffsP.html
http://googletesting.blogspot.com/2009/09/checked-exceptions-i-love-you-but-you.html
For all problems written there, I thought they won't be problems with
noexcept because noexcept is not the default and not written for
specific types.

> that scheme doesn't work at all with templates (what exactly would you
> write?)

Like this:

 template <class T, class Allocator = allocator<T> >
 class vector {
   ...
   iterator erase(const_iterator position) noexcept(
       has_nothrow_copy_constructor<T>::value &&
       has_nothrow_move_constructor<T>::value &&
       has_nothrow_copy_assign<T>::value &&
       has_nothrow_move_assign<T>::value)

For vector::erase(), we have now the following specification.
 Throws: Nothing unless an exception is thrown by the copy constructor,
   move constructor, assignment operator, or move assignment operator
   of T.
The above declaration looks very straightforward based on this
specification. It will give a compile error when erase() is called in a
noexcept(true) function with T which doesn't fulfill the above
conditions. That sounds fine and great.

> and even when it does work more often than not quickly devolves into the
> meaningless "throw(exception)".

I don't think this will be a problem in C++ since such
"throw(exception)" specification is the default (no exceptions
specification). This is very different situation than that in Java.

Programmers won't be forced to write exception specifications until they
write static exception specification for their own function, or they
pass a type for a template which has a static exception specification.

> As often as I hear a C++ programmer
> wish their exception specifications had Java's static semantics, I
> hear a Java programmer wish theirs had non-static semantics.

Static checking with noexcept is very different with Java's static
checking, in that is default or not, that is a type list or a binary.
I think the problem should be reconsidered separately, shouldn't it?

--
k_satoda

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



