make a nothrow call a throwing function

Maxim Fomin maxim at maxim-fomin.ru
Thu Feb 7 12:46:21 PST 2013


On Thursday, 7 February 2013 at 11:38:29 UTC, 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:
>>> 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...

So, you want to call function (which throws) from function marked 
as nothrow? It seems to be breaking idea of what nothrow does.

You can do this in general by casting (which is preferred way) 
and by exploiting current holes/misspecified tricks/corner 
language cases which should be in general avoided. Unfortunately, 
it appears that you cannot cast in your particular case of array 
duplication. However there are other ways to break nothrow and 
you can use them (declaration mismatch, unions, delegates). I 
think the problem is not absence of ways of doing what you want, 
but in limitation of casting with respect to some properties of 
built-in types.

By the way, I would not say that dup array property cannot throw 
exceptions.


More information about the Digitalmars-d-learn mailing list