What is the exact meaning of 'nothrow'?

Yuxuan Shui via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 10 21:44:01 PDT 2015


On Thursday, 11 June 2015 at 00:27:36 UTC, Ali Çehreli wrote:
> On 06/10/2015 05:06 PM, Yuxuan Shui wrote:
>> I want to know exactly what is considered to be 'throw'.
>>
>> I'm able to use dynamic arrays (which can throw 'Range 
>> violation') and
>> asserts in a nothrow function. Shouldn't those be considered 
>> 'throw'?
>
> Yes, the documentation is minimal: :)
>
>   http://dlang.org/function.html#nothrow-functions
>
> It says "Nothrow functions do not throw any exceptions derived 
> from class Exception."
>
> I have more information here but the language is misleading:
>
>   
> http://ddili.org/ders/d.en/functions_more.html#ix_functions_more.nothrow
>
> I am going to add something like the following to clarify:
>
> "Note: Remember that it is not recommended to catch Error nor 
> its base class Throwable. What I mean by "any exception" here 
> is "any exception that is defined under the Exception 
> hierarchy." A nothrow function can still emit exceptions that 
> are under the Error hierarchy, which represents irrecoverable 
> error conditions that should preclude the program from 
> continuing its execution."
>
> In other words, nothrow means "does not emit Exception, it can 
> still emit Error."
>
> Ali

Thanks, that clear things up.


More information about the Digitalmars-d-learn mailing list