www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Make function nothrow

reply ref2401 <refactor24 gmail.com> writes:
There are functions in Phobos that do not throw but they are not 
marked as `nothrow`.
When I need to call them from my `nothrow` code I do this:

void foo() { /* I won't throw, honestly. */ }

void bar() nothrow {
	scope(failure) assert(false);
	foo();
}

The question is: Is it ok to do such thing or should I just stick 
with try {} catch() {}?
Thank you.
Jan 28 2016
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 01/28/2016 08:05 AM, ref2401 wrote:
 There are functions in Phobos that do not throw but they are not marked
 as `nothrow`.
 When I need to call them from my `nothrow` code I do this:

 void foo() { /* I won't throw, honestly. */ }

 void bar() nothrow {
      scope(failure) assert(false);
      foo();
 }

 The question is: Is it ok to do such thing or should I just stick with
 try {} catch() {}?
 Thank you.
There is assumeWontThrow which terminates if an exception is indeed thrown: http://dlang.org/library/std/exception/assume_wont_throw.html Ali
Jan 28 2016
parent ref2401 <refactor24 gmail.com> writes:
On Thursday, 28 January 2016 at 16:22:23 UTC, Ali Çehreli wrote:
 There is assumeWontThrow which terminates if an exception is 
 indeed thrown:

   http://dlang.org/library/std/exception/assume_wont_throw.html

 Ali
nice one, thx
Jan 28 2016