Article View: comp.std.c++
Article #2834Re: throw declarations
From: J. Kanze
Date: Mon, 04 Dec 1995 22:38
Date: Mon, 04 Dec 1995 22:38
52 lines
2197 bytes
2197 bytes
Joe Walker (walkerjj@ecid.cig.mot.com) wrote:
|> As I understand the DWP this is legal:
|> void func () throw ()
|> {
|> throw 1;
|> }
|> The question is, why?
|> Surely this should be a compiler error.
|> What is the justification for this?
Basically for the same reason that returning a reference to a local
variable isn't a compiler error. It is practically impossible for the
compiler to detect in the general case, and practically impossible to
find wording exact enough for a standard to define when it must be
detected by the compiler, and when the compiler is not required to
detect it.
Consider the following:
extern void g( int ) throw (int ) ;
void
f() throw()
{
g( 0 ) ;
}
Should the compiler complain here? Apparently, f() may throw an
exception (through g). But suppose in fact that I know that g cannot
throw an exception if the parameter is 0. Should I still be required to
enclose it in a try block, to shut up the compiler?
In the direct case that you give as an example, I would imagine that any
reasonable compiler will generate a warning, the same as they do if you
blatantly return the address of a local variable. (Note that in both
cases, there are potentially reasons why you might *want* to do this.)
--
James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils, études et réalisations en logiciel orienté objet --
-- A la recherche d'une activité dans une region francophone
---
[ 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:
<49ug4r$hqc@gabi.gabi-soft.fr>Path:
arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!MattReferences:
<30BEE97F.41C67EA6@ecid.cig.mot.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt From: kanze@gabi-soft.fr (J. Kanze) Newsgroups: comp.std.c++ Subject: Re: throw declarations Date: 04 Dec 1995 22:38:09 GMT Organization: GABI Software, Sarl. Approved: Matt@Austern Message-ID: <49ug4r$hqc@gabi.gabi-soft.fr> References: <30BEE97F.41C67EA6@ecid.cig.mot.com> NNTP-Posting-Host: austern.hip.berkeley.edu