Article View: comp.std.c++
Article #2614Re: ubiquitous exception specs?
From: dak
Date: Wed, 15 Nov 1995 18:03
Date: Wed, 15 Nov 1995 18:03
42 lines
2273 bytes
2273 bytes
In a previous artivle, Herb Sutter wrote: > > In article <9511120523.14310@mulga.cs.mu.OZ.AU>, > fjh@munta.cs.mu.OZ.AU (Fergus Henderson) wrote: > >herbs@interlog.com (Herb Sutter) writes: > >>While we're on the subject of exception handling, is there any technical > >>reason not to have an exception spec on every member function of every > class? > > > >There is at least one technical reason - it won't work with template > >classes. Consider, for example, the member functions of the STL > >collection classes. What exception specification should they have? > > Hmm... good point, but while this is a good argument in the case of collection > classes, is it necessarily true of all template classes? > 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). The real problem is exception enforcement: a function without a throw clause can throw any exception, but then again, maybe not. Thus the compiler cannot enforce anything on such code. This is true for any class, and each time the designer must decide if he wish to enforce a particular exception or let the door open for anything to happen. The fact that types used in template are unknown and may throw any exception doesn't change that fact: either you put a catch expression on each usage of the sub-type, or let the unexpected exception handler do the job or you don't specify exceptions that can be thrown. - the biggest problem with C++ is its popularity. dak@cae.ca --- [ 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:
<Pine.A32.3.91.951115085701.21991A-100000@zorglub.cae.ca>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: dak <pierreba@poster.cae.ca> Newsgroups: comp.std.c++ Subject: Re: ubiquitous exception specs? Date: 15 Nov 1995 18:03:17 GMT Organization: <none> Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <Pine.A32.3.91.951115085701.21991A-100000@zorglub.cae.ca> NNTP-Posting-Host: physics2.berkeley.edu