🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: throw declarations

#2815
From: Steve Clamage
Date: Sat, 02 Dec 1995 10:04
42 lines
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. ]
Technical Details
Message-ID: <49o329$p71@engnews1.eng.sun.com>
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
References: <30BEE97F.41C67EA6@ecid.cig.mot.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: throw declarations
Date: 02 Dec 1995 10:04:07 GMT
Organization: Sun Microsystems Inc.
Approved: Matt@Austern
Message-ID: <49o329$p71@engnews1.eng.sun.com>
References: <30BEE97F.41C67EA6@ecid.cig.mot.com>
Reply-To: clamage@Eng.Sun.COM
NNTP-Posting-Host: austern.hip.berkeley.edu