What is nothrow for?

Christopher Wright dhasenan at gmail.com
Fri Apr 25 17:37:49 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

It's a usability argument that Janice is making. She isn't saying that 
nothrow lacks benefits.



More information about the Digitalmars-d mailing list