🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Claus Andre Faerber Thu, 14 Dec 1995 17:37
Re: throw declarations
#2931
Author: Claus Andre Faerber
Date: Thu, 14 Dec 1995 17:37
27 lines
2017 bytes
clamage@Eng.sun.com (08 Dec 95):

> The current rule, related to the original question, is that function f4
> is OK, and an error results only if g actually exits via an exception.
> The alternative would be to require that every function called have an
> exception specification at least as restrictive as the calling function.

... or a try-catch statement, which catches other exceptions and must not  
re-throw them.

> Such a rule would make exceptions specifications completely useless.

If a function can throw an exception although it was declared as throw(),  
what's the point of having such a throw declaration at all ??
Wether a function can throw an exception or not could be documented with  
the meaning of the function parameters and the use of the function.
Why does the compiler need to be told this, if it doesn't do anything to  
prevent functions from behaving differently ??

================================================================================
 Claus Andre Faerber                                     <claus@faerber.muc.de>
================================================================================
## CrossPoint v3.1 ##

[ 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
#2930
Author: Steve Clamage
Date: Thu, 14 Dec 1995 18:25
49 lines
3036 bytes
In article 5zlIdu73cDB@faerber.muc.de, claus@faerber.muc.de (Claus Andre Faerber) writes:
>clamage@Eng.sun.com (08 Dec 95):
>
>> The current rule, related to the original question, is that function f4
>> is OK, and an error results only if g actually exits via an exception.
>> The alternative would be to require that every function called have an
>> exception specification at least as restrictive as the calling function.
>
>.... or a try-catch statement, which catches other exceptions and must not  
>re-throw them.

Of course, but that is in general the case anyway.

>> Such a rule would make exceptions specifications completely useless.
>
>If a function can throw an exception although it was declared as throw(),  
>what's the point of having such a throw declaration at all ??
>Wether a function can throw an exception or not could be documented with  
>the meaning of the function parameters and the use of the function.
>Why does the compiler need to be told this, if it doesn't do anything to  
>prevent functions from behaving differently ??

A throw specification is a promise from the programmer to the compiler
(and to users of the code) that the function will not throw any other
exceptions. The compiler is allowed to generate code on that assumption,
but for one thing: the current version of unexpected() must be called in
the event of a disallowed exception escaping the function. So the compiler
has one extra chore: at the point where an exception escapes from a
function having an exception specification, the compiler might need to add
a test for validity.

You actually have an additional option. If a function f calls another
function g which has a less restrictive throw specification, function
f can install an unexpected-handler that converts a disallowed
exception into one which is allowed by f's throw specification. That would
be the moral equivalent of f catching the exception itself, but it
allows you to write function f without cluttering it with unrelated catch
clauses; a single version of "unexpected" could serve the needs of a
collection of functions. Or you could let the program terminate, which
is the default action anyway.

---
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. ]
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