What is nothrow for?

Yigal Chripun yigal100 at gmail.com
Fri Apr 25 06:26:45 PDT 2008


Walter Bright wrote:
> Janice Caron wrote:
>> So I guess my question is, in what circumstance would "nothrow" be
>> helpful? And is it helpful /enough/ to warrant "polluting" all library
>> code with "nothrow" annotations?
> 
> "nothrow" is, as you say, a contract. It specifies that a function must
> return normally (unless it aborts, crashes, or hangs). Such annotations:
> 
> 1. improves the API documentation
> 2. enables significantly better code generation (if you use a lot of
> scope statements and struct destructors)
> 3. nothrow can be very useful in building up transactions, because you
> know that the components cannot fail
> 4. destructors cannot throw exceptions (because they are already in
> one). Andrei has proposed a method to deal with this, but it is as yet
> unimplemented.
> 
> For more info, see http://www.gotw.ca/gotw/082.htm and
> http://www.boost.org/community/exception_safety.html

I'd like to point out that you both agree that "nothrow" is a
_contract_. That immediately begs the question: why implement it as yet
another ad hoc feature instead of making it part of D's DBC (which is
yet to be implemented...)?

Personally, I don't see the point of constantly adding more annotations
and keywords to D2 since it complicates the syntax and makes D2 much
less attractive from a syntax POV.
D2 will allow the following:
pure invariant invariant(int) func(invariant(int)) nothrow;
Am I the only one that thinks the above is too much?

It's time for a standardized Annotations/Attributes mechanism for D.
I'll post my initial suggestion for such a mechanism in a new thread.

--Yigal



More information about the Digitalmars-d mailing list