On 02/07/2013 05:38 AM, monarch_dodra wrote:
On Thursday, 7 February 2013 at 10:55:26 UTC, Jonathan M Davis wrote:
On Thursday, February 07, 2013 11:06:14 monarch_dodra wrote:
Is there any way that a nothrow function can call a function that
throws, but without even trying to catch if an exception is
thrown?
My use case is a pretty low level nothrow function, that needs to
call something that never ever throws, but was not marked as such.
I want to avoid the "try/catch/[do nothing|assert]" because I
don't want to pay for that. Ideally, i'd really just want to mark
my function as nothrow, and have undefined behavior if it *does*
throw.
Any way to do that?
You can cast the function.
- Jonathan M Davis
Smart.
Unfortunatly, in this case, I'm trying to call "string.dup".
It would appear though that (apparently), dup is a property that returns
a function pointer, or something. In any case, I can't seem to be able
to get its address.
Now I feel kind of bad for suggesting banning taking the address of a
property function ...
I can bypass this with a wrapper function I guess, but at this point,
I'd have to bench to see if that is even worth it...
scope(failure) has worked for me in the past, but mostly calling C
functions from nothrow.
You do have to put it at the top of the function, but it's simple and nice.