Thread View: comp.std.c++
3 messages
3 total messages
Started by Joe Walker
Fri, 01 Dec 1995 19:17
throw declarations
Author: Joe Walker
Date: Fri, 01 Dec 1995 19:17
Date: Fri, 01 Dec 1995 19:17
28 lines
1001 bytes
1001 bytes
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?
TA,
Joe.
--
____
|___ | ___ ___ EMail: walkerjj@sweng.ecid.cig.mot.com
_ | |/ _ \| __| SMail: Motorola, 16 Euroway, Blagrove, SWINDON SN58YQ
| |_| | (_) | _| Tel: [+44/0] 793 54 5346
\___/ \___/|___| Fax: [+44/0] 793 54 1228
---
[ 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. ]
Re: throw declarations
Author: Steve Clamage
Date: Sat, 02 Dec 1995 10:04
Date: Sat, 02 Dec 1995 10:04
42 lines
1450 bytes
1450 bytes
In article 41C67EA6@ecid.cig.mot.com, Joe Walker <walkerjj@ecid.cig.mot.com> writes:
>
>As I understand the DWP this is legal:
>
> void func () throw ()
> {
> throw 1;
> }
>
>The question is, why?
>Surely this should be a compiler error.
It is an error if the throw statement is executed, but not otherwise.
That is, "func" might not ever be called.
That may sound like nit-picking, but it avoids having to
decide whether examples like the following are valid:
void f1(int j) throw()
{
if( j == 0 )
throw 1; // the programmer believes j is always > 0
}
#include <math>
void f2(unsigned x) throw()
{
if( std::sqrt((double)x) ) < 0.0 )
throw 1; // really can't happen, but must compiler deduce that?
}
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ 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. ]
Re: throw declarations
Author: 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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads