Article View: comp.std.c++
Article #2694Re: ubiquitous exception specs?
From: Fergus Henderson
Date: Tue, 21 Nov 1995 16:02
Date: Tue, 21 Nov 1995 16:02
43 lines
2672 bytes
2672 bytes
dak <pierreba@poster.cae.ca> writes:
>Why shouldn't templates have exception specified ? Saying that it depends on
>the types used in the template instance seems gibberish to me: you could say
>the same for any class that use any other class (eitehr publicly or in its
>implementation).
Part of the problem is that the C++ language is not powerful enough to
express the right exception specifications for even simple templates.
For example, what should the exception specification for the following
template be?
template <class T> T add3 (T a, T b, T c) { return a + b + c; }
Using exception specifications is a trade-off, just like using
a strongly typed language is a trade-off. Strong types are great
if the type system is powerful enough (e.g. it includes templates
or some equivalent functionality), but if it is not, they can
be a real straight-jacket.
A coding standard which required the use of exception specifications
on all templates would also be a straight-jacked, because it would
make it difficult or impossible to write/use a lot of simple and useful
templates.
Another part of the problem is that even if the C++ language
was powerful enough to express appropriate exception specifications for
templates, the declarations might be complex, long-winded, and thus
might in the end not be worth the effort. The additional development
and maintenance cost of writing and maintaining the declarations might
not be worth whatever benefit it buys you in terms of preventing
unexpected exceptions. In the case of non-template functions, the
declarations are usually simpler, and so the trade-off is different -
using exception specifications might be worthwhile in the simple case,
but might not be worthwhile in the case of templates.
--
Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<9532600.2461@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<Pine.A32.3.91.951115085701.21991A-100000@zorglub.cae.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Newsgroups: comp.std.c++ Subject: Re: ubiquitous exception specs? Date: 21 Nov 1995 16:02:49 GMT Organization: Computer Science, University of Melbourne, Australia Sender: news@cs.mu.OZ.AU (CS-Usenet) Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <9532600.2461@mulga.cs.mu.OZ.AU> References: <Pine.A32.3.91.951115085701.21991A-100000@zorglub.cae.ca> NNTP-Posting-Host: taumet.eng.sun.com Originator: clamage@taumet