make a nothrow call a throwing function

Jonathan M Davis jmdavisProg at gmx.com
Thu Feb 7 13:32:13 PST 2013


On Thursday, February 07, 2013 21:46:21 Maxim Fomin wrote:
> So, you want to call function (which throws) from function marked
> as nothrow? It seems to be breaking idea of what nothrow does.

I believe that the problem is that the function isn't marked nothrow even 
though it doesn't throw. He essentially wants to be able to make the compiler 
treat it as nothrow at the call site (since he can't change the function 
definition) without any overhead, and I don't think that that's actually 
possible.

The normal way to handle cases where you know that a function won't throw but 
isn't nothrow is to wrap it in a try block and put an assert(0) statement in 
the catch block. That does incur some amound of overhead, but I don't know how 
much. Apparently, monarch_dodra thinks that it's too much for what he's doing 
though.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list