make a nothrow call a throwing function

monarch_dodra monarchdodra at gmail.com
Thu Feb 7 03:38:28 PST 2013


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...


More information about the Digitalmars-d-learn mailing list