🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2879

Re: throw declarations

#2879
From: dak
Date: Thu, 07 Dec 1995 18:28
62 lines
2328 bytes

clamage@Eng.Sun.COM (Steve Clamage) wrote:
> 
> 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.
> 
But how does this affect the fact that it throws when it says it doesn't ?
A function returning the wrong type will cause a compiler disgnostic even
if it is never called (it could be checked at run time...)

> 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?
> }



Why the need to decide ? Again, comparison with return value, IMO, shows
that not to be a valid reason. I believed that the real reason was to
somehow relax the design of templates and allow a wider range of types to
be use (and resolve any design error at run-time). All time seems quite
contrary to the rest of the C++ design which is to check things at
compile time.

While I understand that some people may think it necessary to allow
non-throwing functions to call functions without throw specs, or even
functions with throw specs, I don't see how it can extent to actual throw
expression...

So am I right to think the rule was decided upon due to templates ?




---
[ 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.951207084521.21417B-100000@zorglub.cae.ca>
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
From: dak <pierreba@poster.cae.ca>
Newsgroups: comp.std.c++
Subject: Re: throw declarations
Date: 07 Dec 1995 18:28:52 GMT
Organization: <none>
Approved: Matt@Austern
Message-ID: <Pine.A32.3.91.951207084521.21417B-100000@zorglub.cae.ca>
NNTP-Posting-Host: austern.hip.berkeley.edu